You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by ha...@apache.org on 2023/01/18 13:46:25 UTC

[skywalking-banyandb] branch query-optimize created (now 1ed57a26)

This is an automated email from the ASF dual-hosted git repository.

hanahmily pushed a change to branch query-optimize
in repository https://gitbox.apache.org/repos/asf/skywalking-banyandb.git


      at 1ed57a26 Introduce the optimization phase

This branch includes the following new commits:

     new 1ed57a26 Introduce the optimization phase

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[skywalking-banyandb] 01/01: Introduce the optimization phase

Posted by ha...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

hanahmily pushed a commit to branch query-optimize
in repository https://gitbox.apache.org/repos/asf/skywalking-banyandb.git

commit 1ed57a26d9c39d038d560a6d0c48f14acc17ef7f
Author: Gao Hongtao <ha...@gmail.com>
AuthorDate: Wed Jan 18 13:39:39 2023 +0000

    Introduce the optimization phase
    
    Signed-off-by: Gao Hongtao <ha...@gmail.com>
---
 dist/LICENSE                                       |  67 +--
 ...vue-compiler-sfc-node-modules-magic-string.txt} |   0
 ...tivity-transform-node-modules-magic-string.txt} |   0
 dist/licenses/ui-licenses/license-sass.txt         | 584 +++++++++------------
 pkg/query/logical/common.go                        |  13 +
 pkg/query/logical/measure/measure_analyzer.go      |  57 +-
 .../measure/measure_plan_indexscan_local.go        | 106 ++--
 pkg/query/logical/measure/schema.go                |   6 +-
 pkg/query/logical/optimizer.go                     | 102 ++++
 pkg/query/logical/plan.go                          | 131 ++---
 pkg/query/logical/plan_orderby.go                  | 101 ----
 pkg/query/logical/stream/stream_analyzer.go        | 151 +++++-
 .../logical/stream/stream_plan_indexscan_local.go  |  36 +-
 pkg/query/logical/stream/stream_plan_tag_filter.go |  33 +-
 test/cases/measure/data/want/bottom.yaml           |  44 +-
 test/cases/measure/data/want/top.yaml              |  44 +-
 ui/LICENSE                                         |  67 +--
 17 files changed, 778 insertions(+), 764 deletions(-)

diff --git a/dist/LICENSE b/dist/LICENSE
index a60b3a96..2e538438 100644
--- a/dist/LICENSE
+++ b/dist/LICENSE
@@ -369,7 +369,7 @@ The text of each license is also included at licenses/ui-licenses/LICENSE-[proje
 Apache-2.0 licenses
 ========================================================================
 
-    echarts 5.3.3 Apache-2.0
+    echarts 5.4.1 Apache-2.0
 
 ========================================================================
 BSD-3-Clause licenses
@@ -378,13 +378,13 @@ BSD-3-Clause licenses
     normalize-wheel-es 1.2.0 BSD-3-Clause
     source-map 0.6.1 BSD-3-Clause
     source-map-js 1.0.2 BSD-3-Clause
-    zrender 5.3.2 BSD-3-Clause
+    zrender 5.4.1 BSD-3-Clause
 
 ========================================================================
 ISC licenses
 ========================================================================
 
-    anymatch 3.1.2 ISC
+    anymatch 3.1.3 ISC
     glob-parent 5.1.2 ISC
     graceful-fs 4.2.10 ISC
     picocolors 1.0.0 ISC
@@ -393,30 +393,32 @@ ISC licenses
 MIT licenses
 ========================================================================
 
-    @babel/parser 7.19.1 MIT
-    @ctrl/tinycolor 3.4.1 MIT
+    @babel/parser 7.20.7 MIT
+    @ctrl/tinycolor 3.5.0 MIT
     @element-plus/icons-vue 2.0.10 MIT
-    @floating-ui/core 1.0.1 MIT
-    @floating-ui/dom 1.0.1 MIT
+    @floating-ui/core 1.1.0 MIT
+    @floating-ui/dom 1.1.0 MIT
     @popperjs/core 2.11.7 MIT
-    @types/lodash 4.14.185 MIT
+    @types/lodash 4.14.191 MIT
     @types/lodash-es 4.17.6 MIT
-    @types/web-bluetooth 0.0.15 MIT
-    @vue/compiler-core 3.2.39 MIT
-    @vue/compiler-dom 3.2.39 MIT
-    @vue/compiler-sfc 3.2.39 MIT
-    @vue/compiler-ssr 3.2.39 MIT
-    @vue/devtools-api 6.2.1 MIT
-    @vue/reactivity 3.2.39 MIT
-    @vue/reactivity-transform 3.2.39 MIT
-    @vue/runtime-core 3.2.39 MIT
-    @vue/runtime-dom 3.2.39 MIT
-    @vue/server-renderer 3.2.39 MIT
-    @vue/shared 3.2.39 MIT
-    @vueuse/core 9.2.0 MIT
+    @types/web-bluetooth 0.0.16 MIT
+    @vue/compiler-core 3.2.45 MIT
+    @vue/compiler-dom 3.2.45 MIT
+    @vue/compiler-sfc 3.2.45 MIT
+    @vue/compiler-sfc/node_modules/magic-string 0.25.9 MIT
+    @vue/compiler-ssr 3.2.45 MIT
+    @vue/devtools-api 6.4.5 MIT
+    @vue/reactivity 3.2.45 MIT
+    @vue/reactivity-transform 3.2.45 MIT
+    @vue/reactivity-transform/node_modules/magic-string 0.25.9 MIT
+    @vue/runtime-core 3.2.45 MIT
+    @vue/runtime-dom 3.2.45 MIT
+    @vue/server-renderer 3.2.45 MIT
+    @vue/shared 3.2.45 MIT
+    @vueuse/core 9.10.0 MIT
     @vueuse/core/node_modules/vue-demi 0.13.11 MIT
-    @vueuse/metadata 9.2.0 MIT
-    @vueuse/shared 9.2.0 MIT
+    @vueuse/metadata 9.10.0 MIT
+    @vueuse/shared 9.10.0 MIT
     @vueuse/shared/node_modules/vue-demi 0.13.11 MIT
     async-validator 4.2.5 MIT
     asynckit 0.4.0 MIT
@@ -426,15 +428,15 @@ MIT licenses
     chokidar 3.5.3 MIT
     combined-stream 1.0.8 MIT
     csstype 2.6.21 MIT
-    dayjs 1.11.5 MIT
+    dayjs 1.11.7 MIT
     delayed-stream 1.0.0 MIT
-    element-plus 2.2.17 MIT
+    element-plus 2.2.28 MIT
     escape-html 1.0.3 MIT
     estree-walker 2.0.2 MIT
     fill-range 7.0.1 MIT
     follow-redirects 1.15.2 MIT
     form-data 4.0.0 MIT
-    immutable 4.1.0 MIT
+    immutable 4.2.2 MIT
     is-binary-path 2.1.0 MIT
     is-extglob 2.1.1 MIT
     is-glob 4.0.3 MIT
@@ -442,8 +444,7 @@ MIT licenses
     jsonfile 6.1.0 MIT
     lodash 4.17.21 MIT
     lodash-es 4.17.21 MIT
-    lodash-unified 1.0.2 MIT
-    magic-string 0.25.9 MIT
+    lodash-unified 1.0.3 MIT
     memoize-one 6.0.0 MIT
     mime-db 1.52.0 MIT
     mime-types 2.1.35 MIT
@@ -451,13 +452,13 @@ MIT licenses
     nanoid 3.3.4 MIT
     normalize-path 3.0.0 MIT
     picomatch 2.3.1 MIT
-    pinia 2.0.22 MIT
+    pinia 2.0.28 MIT
     pinia/node_modules/vue-demi 0.13.11 MIT
-    postcss 8.4.16 MIT
+    postcss 8.4.21 MIT
     readdirp 3.6.0 MIT
-    sass 1.54.9 MIT
+    sass 1.57.1 MIT
     sourcemap-codec 1.4.8 MIT
     to-regex-range 5.0.1 MIT
     universalify 2.0.0 MIT
-    vue 3.2.39 MIT
-    vue-router 4.1.5 MIT
+    vue 3.2.45 MIT
+    vue-router 4.1.6 MIT
diff --git a/dist/licenses/ui-licenses/license-magic-string.txt b/dist/licenses/ui-licenses/license--vue-compiler-sfc-node-modules-magic-string.txt
similarity index 100%
copy from dist/licenses/ui-licenses/license-magic-string.txt
copy to dist/licenses/ui-licenses/license--vue-compiler-sfc-node-modules-magic-string.txt
diff --git a/dist/licenses/ui-licenses/license-magic-string.txt b/dist/licenses/ui-licenses/license--vue-reactivity-transform-node-modules-magic-string.txt
similarity index 100%
rename from dist/licenses/ui-licenses/license-magic-string.txt
rename to dist/licenses/ui-licenses/license--vue-reactivity-transform-node-modules-magic-string.txt
diff --git a/dist/licenses/ui-licenses/license-sass.txt b/dist/licenses/ui-licenses/license-sass.txt
index 504a4802..6548d00c 100644
--- a/dist/licenses/ui-licenses/license-sass.txt
+++ b/dist/licenses/ui-licenses/license-sass.txt
@@ -182,7 +182,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 --------------------------------------------------------------------------------
 
-async, cli_util, collection, mime and typed_data license:
+async, cli_util, collection, mime, source_map_stack_trace, stream_channel and
+typed_data license:
 
 Copyright 2015, the Dart project authors. 
 
@@ -215,9 +216,10 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 --------------------------------------------------------------------------------
 
-boolean_selector and test_descriptor license:
+boolean_selector, meta and shelf_packages_handler license:
+
+Copyright 2016, the Dart project authors.
 
-Copyright 2016, the Dart project authors. All rights reserved.
 Redistribution and use in source and binary forms, with or without
 modification, are permitted provided that the following conditions are
 met:
@@ -228,7 +230,7 @@ met:
       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 Google Inc. nor the names of its
+    * Neither the name of Google LLC nor the names of its
       contributors may be used to endorse or promote products derived
       from this software without specific prior written permission.
 
@@ -247,7 +249,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 --------------------------------------------------------------------------------
 
-charcode, oauth2, source_maps and stack_trace license:
+charcode license:
 
 Copyright 2014, the Dart project authors. All rights reserved.
 Redistribution and use in source and binary forms, with or without
@@ -581,215 +583,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 --------------------------------------------------------------------------------
 
-coverage and quiver 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 [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.
-
---------------------------------------------------------------------------------
-
-dart_style, dartdoc, glob, http, http_parser, matcher, path, pool, pub_semver,
-source_span, string_scanner, test and watcher license:
+coverage, dart_style, dartdoc, glob, http, http_parser, matcher, path, pool,
+pub_semver, source_span, string_scanner, test and watcher license:
 
 Copyright 2014, the Dart project authors. 
 
@@ -853,32 +648,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 --------------------------------------------------------------------------------
 
-freezed_annotation license:
-
-MIT License
-
-Copyright (c) 2020 Remi Rousselet
-
-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.
-
---------------------------------------------------------------------------------
-
 frontend_server_client license:
 
 Copyright 2020, the Dart project authors. 
@@ -964,7 +733,7 @@ Adam Barth - abarth@webkit.org
 Eric Seidel - eric@webkit.org
 The Mozilla Foundation (contributions from Henri Sivonen since 2008)
 David Flanagan (Mozilla) - dflanagan@mozilla.com
-Google Inc. (contributed the Dart port) - misc@dartlang.org
+Google LLC (contributed the Dart port) - misc@dartlang.org
 
 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:
 
@@ -975,7 +744,8 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
 
 --------------------------------------------------------------------------------
 
-http_multi_server, shelf and shelf_web_socket license:
+http_multi_server, oauth2, shelf, shelf_web_socket, source_maps and stack_trace
+license:
 
 Copyright 2014, the Dart project authors.
 
@@ -1008,7 +778,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 --------------------------------------------------------------------------------
 
-io and term_glyph license:
+io, stream_transform and term_glyph license:
 
 Copyright 2017, the Dart project authors. 
 
@@ -1074,7 +844,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 --------------------------------------------------------------------------------
 
-json_annotation and stream_transform license:
+json_annotation license:
 
 Copyright 2017, the Dart project authors. All rights reserved.
 Redistribution and use in source and binary forms, with or without
@@ -1172,54 +942,21 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 --------------------------------------------------------------------------------
 
-meta and shelf_packages_handler license:
+node_interop license:
 
-Copyright 2016, the Dart project authors.
+Copyright (c) 2017, Anatoly Pulyaevskiy.
+All rights reserved.
 
 Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions are
-met:
-
+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 Google LLC 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.
-
-
---------------------------------------------------------------------------------
-
-node_interop license:
-
-Copyright (c) 2017, Anatoly Pulyaevskiy.
-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 the <organization> nor the
-      names of its contributors may be used to endorse or promote products
-      derived from this software without specific prior written permission.
+    * 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 the <organization> 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
@@ -1348,6 +1085,32 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 THE SOFTWARE.
 
 
+--------------------------------------------------------------------------------
+
+pointycastle license:
+
+
+Copyright (c) 2000 - 2019 The Legion of the Bouncy Castle Inc. (https://www.bouncycastle.org)
+
+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.
+
+
+
 --------------------------------------------------------------------------------
 
 pub_api_client license:
@@ -1440,9 +1203,217 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 --------------------------------------------------------------------------------
 
-source_map_stack_trace and stream_channel license:
+quiver and retry 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 [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.
+
+--------------------------------------------------------------------------------
+
+test_descriptor and web_socket_channel license:
+
+Copyright 2016, the Dart project authors. 
 
-Copyright 2015, the Dart project authors. All rights reserved.
 Redistribution and use in source and binary forms, with or without
 modification, are permitted provided that the following conditions are
 met:
@@ -1453,7 +1424,7 @@ met:
       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 Google Inc. nor the names of its
+    * Neither the name of Google LLC nor the names of its
       contributors may be used to endorse or promote products derived
       from this software without specific prior written permission.
 
@@ -1560,39 +1531,6 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 
---------------------------------------------------------------------------------
-
-web_socket_channel license:
-
-Copyright 2016, the Dart project authors. 
-
-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 Google LLC 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.
-
-
 --------------------------------------------------------------------------------
 
 yaml license:
diff --git a/pkg/query/logical/common.go b/pkg/query/logical/common.go
index c5c754c5..1d738466 100644
--- a/pkg/query/logical/common.go
+++ b/pkg/query/logical/common.go
@@ -180,6 +180,19 @@ func (t *Tag) getFamilyName() string {
 	return t.familyName
 }
 
+// ToTags converts a projection spec to Tag sets.
+func ToTags(projection *modelv1.TagProjection) [][]*Tag {
+	projTags := make([][]*Tag, len(projection.GetTagFamilies()))
+	for i, tagFamily := range projection.GetTagFamilies() {
+		var projTagInFamily []*Tag
+		for _, tagName := range tagFamily.GetTags() {
+			projTagInFamily = append(projTagInFamily, NewTag(tagFamily.GetName(), tagName))
+		}
+		projTags[i] = projTagInFamily
+	}
+	return projTags
+}
+
 // Field identity a field in a measure.
 type Field struct {
 	Name string
diff --git a/pkg/query/logical/measure/measure_analyzer.go b/pkg/query/logical/measure/measure_analyzer.go
index 9433065c..a8f6150b 100644
--- a/pkg/query/logical/measure/measure_analyzer.go
+++ b/pkg/query/logical/measure/measure_analyzer.go
@@ -23,7 +23,6 @@ import (
 	commonv1 "github.com/apache/skywalking-banyandb/api/proto/banyandb/common/v1"
 	measurev1 "github.com/apache/skywalking-banyandb/api/proto/banyandb/measure/v1"
 	"github.com/apache/skywalking-banyandb/banyand/measure"
-	"github.com/apache/skywalking-banyandb/banyand/tsdb"
 	"github.com/apache/skywalking-banyandb/pkg/query/logical"
 )
 
@@ -75,10 +74,7 @@ func Analyze(_ context.Context, criteria *measurev1.QueryRequest, metadata *comm
 	}
 
 	// parse fields
-	plan, err := parseFields(criteria, metadata, s, groupByEntity)
-	if err != nil {
-		return nil, err
-	}
+	plan := parseFields(criteria, metadata, groupByEntity)
 
 	if criteria.GetGroupBy() != nil {
 		plan = newUnresolvedGroupBy(plan, groupByTags, groupByEntity)
@@ -102,51 +98,30 @@ func Analyze(_ context.Context, criteria *measurev1.QueryRequest, metadata *comm
 		limitParameter = defaultLimit
 	}
 	plan = limit(plan, criteria.GetOffset(), limitParameter)
-
-	return plan.Analyze(s)
+	p, err := plan.Analyze(s)
+	if err != nil {
+		return nil, err
+	}
+	rules := []logical.OptimizeRule{
+		logical.NewPushDownOrder(criteria.OrderBy),
+		logical.NewPushDownMaxSize(int(limitParameter + criteria.GetOffset())),
+	}
+	if err := logical.ApplyRules(p, rules...); err != nil {
+		return nil, err
+	}
+	return p, nil
 }
 
 // parseFields parses the query request to decide which kind of plan should be generated
 // Basically,
 // 1 - If no criteria is given, we can only scan all shards
 // 2 - If criteria is given, but all of those fields exist in the "entity" definition.
-func parseFields(criteria *measurev1.QueryRequest, metadata *commonv1.Metadata, s logical.Schema, groupByEntity bool) (logical.UnresolvedPlan, error) {
-	timeRange := criteria.GetTimeRange()
-
-	projTags := make([][]*logical.Tag, len(criteria.GetTagProjection().GetTagFamilies()))
-	for i, tagFamily := range criteria.GetTagProjection().GetTagFamilies() {
-		var projTagInFamily []*logical.Tag
-		for _, tagName := range tagFamily.GetTags() {
-			projTagInFamily = append(projTagInFamily, logical.NewTag(tagFamily.GetName(), tagName))
-		}
-		projTags[i] = projTagInFamily
-	}
-
+func parseFields(criteria *measurev1.QueryRequest, metadata *commonv1.Metadata, groupByEntity bool) logical.UnresolvedPlan {
 	projFields := make([]*logical.Field, len(criteria.GetFieldProjection().GetNames()))
 	for i, fieldNameProj := range criteria.GetFieldProjection().GetNames() {
 		projFields[i] = logical.NewField(fieldNameProj)
 	}
-
-	entityList := s.EntityList()
-	entityMap := make(map[string]int)
-	entity := make([]tsdb.Entry, len(entityList))
-	for idx, e := range entityList {
-		entityMap[e] = idx
-		// fill AnyEntry by default
-		entity[idx] = tsdb.AnyEntry
-	}
-	filter, entities, err := logical.BuildLocalFilter(criteria.GetCriteria(), s, entityMap, entity)
-	if err != nil {
-		return nil, err
-	}
-
-	// parse orderBy
-	queryOrder := criteria.GetOrderBy()
-	var unresolvedOrderBy *logical.UnresolvedOrderBy
-	if queryOrder != nil {
-		unresolvedOrderBy = logical.NewOrderBy(queryOrder.GetIndexRuleName(), queryOrder.GetSort())
-	}
-
+	timeRange := criteria.GetTimeRange()
 	return indexScan(timeRange.GetBegin().AsTime(), timeRange.GetEnd().AsTime(), metadata,
-		filter, entities, projTags, projFields, groupByEntity, unresolvedOrderBy), nil
+		logical.ToTags(criteria.GetTagProjection()), projFields, groupByEntity, criteria.GetCriteria())
 }
diff --git a/pkg/query/logical/measure/measure_plan_indexscan_local.go b/pkg/query/logical/measure/measure_plan_indexscan_local.go
index 27c1fa6c..d6f6a832 100644
--- a/pkg/query/logical/measure/measure_plan_indexscan_local.go
+++ b/pkg/query/logical/measure/measure_plan_indexscan_local.go
@@ -28,6 +28,7 @@ import (
 
 	commonv1 "github.com/apache/skywalking-banyandb/api/proto/banyandb/common/v1"
 	measurev1 "github.com/apache/skywalking-banyandb/api/proto/banyandb/measure/v1"
+	modelv1 "github.com/apache/skywalking-banyandb/api/proto/banyandb/model/v1"
 	"github.com/apache/skywalking-banyandb/banyand/tsdb"
 	"github.com/apache/skywalking-banyandb/pkg/index"
 	"github.com/apache/skywalking-banyandb/pkg/logger"
@@ -39,15 +40,13 @@ import (
 var _ logical.UnresolvedPlan = (*unresolvedIndexScan)(nil)
 
 type unresolvedIndexScan struct {
-	startTime         time.Time
-	endTime           time.Time
-	filter            index.Filter
-	metadata          *commonv1.Metadata
-	unresolvedOrderBy *logical.UnresolvedOrderBy
-	projectionTags    [][]*logical.Tag
-	projectionFields  []*logical.Field
-	entities          []tsdb.Entity
-	groupByEntity     bool
+	startTime        time.Time
+	endTime          time.Time
+	metadata         *commonv1.Metadata
+	criteria         *modelv1.Criteria
+	projectionTags   [][]*logical.Tag
+	projectionFields []*logical.Field
+	groupByEntity    bool
 }
 
 func (uis *unresolvedIndexScan) Analyze(s logical.Schema) (logical.Plan, error) {
@@ -69,8 +68,15 @@ func (uis *unresolvedIndexScan) Analyze(s logical.Schema) (logical.Plan, error)
 		}
 	}
 
-	// resolve sub-plan with the projected view of streamSchema
-	orderBySubPlan, err := uis.unresolvedOrderBy.Analyze(s.ProjTags(projTagsRefs...))
+	entityList := s.EntityList()
+	entityMap := make(map[string]int)
+	entity := make([]tsdb.Entry, len(entityList))
+	for idx, e := range entityList {
+		entityMap[e] = idx
+		// fill AnyEntry by default
+		entity[idx] = tsdb.AnyEntry
+	}
+	filter, entities, err := logical.BuildLocalFilter(uis.criteria, s, entityMap, entity)
 	if err != nil {
 		return nil, err
 	}
@@ -81,20 +87,23 @@ func (uis *unresolvedIndexScan) Analyze(s logical.Schema) (logical.Plan, error)
 		projectionTagsRefs:   projTagsRefs,
 		projectionFieldsRefs: projFieldRefs,
 		metadata:             uis.metadata,
-		filter:               uis.filter,
-		entities:             uis.entities,
+		filter:               filter,
+		entities:             entities,
 		groupByEntity:        uis.groupByEntity,
-		OrderBy:              orderBySubPlan,
 		l:                    logger.GetLogger("query", "measure", uis.metadata.Group, uis.metadata.Name, "local-index"),
 	}, nil
 }
 
-var _ logical.Plan = (*localIndexScan)(nil)
+var (
+	_ logical.Plan          = (*localIndexScan)(nil)
+	_ logical.Sorter        = (*localIndexScan)(nil)
+	_ logical.VolumeLimiter = (*localIndexScan)(nil)
+)
 
 type localIndexScan struct {
-	schema logical.Schema
-	filter index.Filter
-	*logical.OrderBy
+	schema               logical.Schema
+	filter               index.Filter
+	order                *logical.OrderBy
 	metadata             *commonv1.Metadata
 	l                    *logger.Logger
 	timeRange            timestamp.TimeRange
@@ -102,6 +111,15 @@ type localIndexScan struct {
 	projectionFieldsRefs []*logical.FieldRef
 	entities             []tsdb.Entity
 	groupByEntity        bool
+	maxDataPointsSize    int
+}
+
+func (i *localIndexScan) Limit(max int) {
+	i.maxDataPointsSize = max
+}
+
+func (i *localIndexScan) Sort(order *logical.OrderBy) {
+	i.order = order
 }
 
 func (i *localIndexScan) Execute(ec executor.MeasureExecutionContext) (executor.MIterator, error) {
@@ -127,13 +145,13 @@ func (i *localIndexScan) Execute(ec executor.MeasureExecutionContext) (executor.
 		return dummyIter, nil
 	}
 	var builders []logical.SeekerBuilder
-	if i.Index != nil {
+	if i.order.Index != nil {
 		builders = append(builders, func(builder tsdb.SeekerBuilder) {
-			builder.OrderByIndex(i.Index, i.Sort)
+			builder.OrderByIndex(i.order.Index, i.order.Sort)
 		})
 	} else {
 		builders = append(builders, func(builder tsdb.SeekerBuilder) {
-			builder.OrderByTime(i.Sort)
+			builder.OrderByTime(i.order.Sort)
 		})
 	}
 	if i.filter != nil {
@@ -162,16 +180,16 @@ func (i *localIndexScan) Execute(ec executor.MeasureExecutionContext) (executor.
 		projectionFieldsRefs: i.projectionFieldsRefs,
 	}
 	if i.groupByEntity {
-		return newSeriesMIterator(iters, transformContext), nil
+		return newSeriesMIterator(iters, transformContext, i.maxDataPointsSize), nil
 	}
-	it := logical.NewItemIter(iters, i.Sort)
-	return newIndexScanIterator(it, transformContext), nil
+	it := logical.NewItemIter(iters, i.order.Sort)
+	return newIndexScanIterator(it, transformContext, i.maxDataPointsSize), nil
 }
 
 func (i *localIndexScan) String() string {
-	return fmt.Sprintf("IndexScan: startTime=%d,endTime=%d,Metadata{group=%s,name=%s},conditions=%s; projection=%s; order=%s",
+	return fmt.Sprintf("IndexScan: startTime=%d,endTime=%d,Metadata{group=%s,name=%s},conditions=%s; projection=%s; order=%s; limit=%d",
 		i.timeRange.Start.Unix(), i.timeRange.End.Unix(), i.metadata.GetGroup(), i.metadata.GetName(),
-		i.filter, logical.FormatTagRefs(", ", i.projectionTagsRefs...), i.OrderBy)
+		i.filter, logical.FormatTagRefs(", ", i.projectionTagsRefs...), i.order, i.maxDataPointsSize)
 }
 
 func (i *localIndexScan) Children() []logical.Plan {
@@ -185,19 +203,17 @@ func (i *localIndexScan) Schema() logical.Schema {
 	return i.schema.ProjTags(i.projectionTagsRefs...).ProjFields(i.projectionFieldsRefs...)
 }
 
-func indexScan(startTime, endTime time.Time, metadata *commonv1.Metadata, filter index.Filter, entities []tsdb.Entity,
-	projectionTags [][]*logical.Tag, projectionFields []*logical.Field, groupByEntity bool, unresolvedOrderBy *logical.UnresolvedOrderBy,
+func indexScan(startTime, endTime time.Time, metadata *commonv1.Metadata, projectionTags [][]*logical.Tag,
+	projectionFields []*logical.Field, groupByEntity bool, criteria *modelv1.Criteria,
 ) logical.UnresolvedPlan {
 	return &unresolvedIndexScan{
-		startTime:         startTime,
-		endTime:           endTime,
-		metadata:          metadata,
-		filter:            filter,
-		projectionTags:    projectionTags,
-		projectionFields:  projectionFields,
-		entities:          entities,
-		groupByEntity:     groupByEntity,
-		unresolvedOrderBy: unresolvedOrderBy,
+		startTime:        startTime,
+		endTime:          endTime,
+		metadata:         metadata,
+		projectionTags:   projectionTags,
+		projectionFields: projectionFields,
+		groupByEntity:    groupByEntity,
+		criteria:         criteria,
 	}
 }
 
@@ -208,17 +224,20 @@ type indexScanIterator struct {
 	err     error
 	current *measurev1.DataPoint
 	context transformContext
+	max     int
+	num     int
 }
 
-func newIndexScanIterator(inner logical.ItemIterator, context transformContext) executor.MIterator {
+func newIndexScanIterator(inner logical.ItemIterator, context transformContext, max int) executor.MIterator {
 	return &indexScanIterator{
 		inner:   inner,
 		context: context,
+		max:     max,
 	}
 }
 
 func (ism *indexScanIterator) Next() bool {
-	if !ism.inner.HasNext() || ism.err != nil {
+	if !ism.inner.HasNext() || ism.err != nil || ism.num > ism.max {
 		return false
 	}
 	nextItem := ism.inner.Next()
@@ -226,6 +245,7 @@ func (ism *indexScanIterator) Next() bool {
 	if ism.current, err = transform(nextItem, ism.context); err != nil {
 		ism.err = multierr.Append(ism.err, err)
 	}
+	ism.num++
 	return true
 }
 
@@ -248,18 +268,21 @@ type seriesIterator struct {
 	inner   []tsdb.Iterator
 	current []*measurev1.DataPoint
 	index   int
+	num     int
+	max     int
 }
 
-func newSeriesMIterator(inner []tsdb.Iterator, context transformContext) executor.MIterator {
+func newSeriesMIterator(inner []tsdb.Iterator, context transformContext, max int) executor.MIterator {
 	return &seriesIterator{
 		inner:   inner,
 		context: context,
 		index:   -1,
+		max:     max,
 	}
 }
 
 func (ism *seriesIterator) Next() bool {
-	if ism.err != nil {
+	if ism.err != nil || ism.num > ism.max {
 		return false
 	}
 	ism.index++
@@ -278,6 +301,7 @@ func (ism *seriesIterator) Next() bool {
 		}
 		ism.current = append(ism.current, dp)
 	}
+	ism.num++
 	return true
 }
 
diff --git a/pkg/query/logical/measure/schema.go b/pkg/query/logical/measure/schema.go
index 8a337aa9..59656612 100644
--- a/pkg/query/logical/measure/schema.go
+++ b/pkg/query/logical/measure/schema.go
@@ -84,8 +84,10 @@ func (m *schema) ProjFields(fieldRefs ...*logical.FieldRef) logical.Schema {
 	i := 0
 	for _, fr := range fieldRefs {
 		if spec, ok := m.fieldMap[fr.Field.Name]; ok {
-			spec.FieldIdx = i
-			newFieldMap[fr.Field.Name] = spec
+			newFieldMap[fr.Field.Name] = &logical.FieldSpec{
+				FieldIdx: i,
+				Spec:     spec.Spec,
+			}
 		}
 		i++
 	}
diff --git a/pkg/query/logical/optimizer.go b/pkg/query/logical/optimizer.go
new file mode 100644
index 00000000..4ee752b7
--- /dev/null
+++ b/pkg/query/logical/optimizer.go
@@ -0,0 +1,102 @@
+// Licensed to Apache Software Foundation (ASF) under one or more contributor
+// license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright
+// ownership. Apache Software Foundation (ASF) licenses this file to you 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.
+
+package logical
+
+import (
+	modelv1 "github.com/apache/skywalking-banyandb/api/proto/banyandb/model/v1"
+)
+
+// OptimizeRule allows optimizing a Plan based on a rule.
+type OptimizeRule interface {
+	Optimize(Plan) (Plan, error)
+}
+
+// ApplyRules apply OptimizeRules to a Plan.
+func ApplyRules(plan Plan, rules ...OptimizeRule) error {
+	p := plan
+	for _, r := range rules {
+		var err error
+		if p, err = r.Optimize(p); err != nil {
+			return err
+		}
+	}
+	cc := plan.Children()
+	if len(cc) < 1 {
+		return nil
+	}
+	for _, c := range cc {
+		if err := ApplyRules(c, rules...); err != nil {
+			return err
+		}
+	}
+	return nil
+}
+
+// VolumeLimiter controls the volume of a Plan's output.
+type VolumeLimiter interface {
+	Plan
+	Limit(max int)
+}
+
+// Sorter sorts a Plan's output.
+type Sorter interface {
+	Plan
+	Sort(order *OrderBy)
+}
+
+var _ OptimizeRule = (*PushDownOrder)(nil)
+
+// PushDownOrder pushes down the order to a Plan.
+type PushDownOrder struct {
+	order *modelv1.QueryOrder
+}
+
+// NewPushDownOrder returns a new PushDownOrder.
+func NewPushDownOrder(order *modelv1.QueryOrder) PushDownOrder {
+	return PushDownOrder{order: order}
+}
+
+// Optimize a Plan by pushing down the query order.
+func (pdo PushDownOrder) Optimize(plan Plan) (Plan, error) {
+	if v, ok := plan.(Sorter); ok {
+		if order, err := ParseOrderBy(v.Schema(), pdo.order.GetIndexRuleName(), pdo.order.GetSort()); err == nil {
+			v.Sort(order)
+		} else {
+			return nil, err
+		}
+	}
+	return plan, nil
+}
+
+// PushDownMaxSize pushes down the max volume to a Plan.
+type PushDownMaxSize struct {
+	max int
+}
+
+// NewPushDownMaxSize returns a new PushDownMaxSize.
+func NewPushDownMaxSize(max int) PushDownMaxSize {
+	return PushDownMaxSize{max: max}
+}
+
+// Optimize a Plan by pushing down the max volume.
+func (pde PushDownMaxSize) Optimize(plan Plan) (Plan, error) {
+	if v, ok := plan.(VolumeLimiter); ok {
+		v.Limit(pde.max)
+	}
+	return plan, nil
+}
diff --git a/pkg/query/logical/plan.go b/pkg/query/logical/plan.go
index 77876594..b3658f8a 100644
--- a/pkg/query/logical/plan.go
+++ b/pkg/query/logical/plan.go
@@ -20,13 +20,10 @@ package logical
 import (
 	"fmt"
 
-	streamv1 "github.com/apache/skywalking-banyandb/api/proto/banyandb/stream/v1"
-	"github.com/apache/skywalking-banyandb/pkg/query/executor"
-)
+	"github.com/pkg/errors"
 
-var (
-	_ Plan           = (*limit)(nil)
-	_ UnresolvedPlan = (*limit)(nil)
+	databasev1 "github.com/apache/skywalking-banyandb/api/proto/banyandb/database/v1"
+	modelv1 "github.com/apache/skywalking-banyandb/api/proto/banyandb/model/v1"
 )
 
 // Parent refers to a parent node in the execution tree(plan).
@@ -35,105 +32,55 @@ type Parent struct {
 	Input           Plan
 }
 
-type limit struct {
-	*Parent
-	LimitNum uint32
+// OrderBy is the sorting operator.
+type OrderBy struct {
+	Index     *databasev1.IndexRule
+	fieldRefs []*TagRef
+	Sort      modelv1.Sort
 }
 
-func (l *limit) Execute(ec executor.StreamExecutionContext) ([]*streamv1.Element, error) {
-	entities, err := l.Parent.Input.(executor.StreamExecutable).Execute(ec)
-	if err != nil {
-		return nil, err
-	}
-
-	if len(entities) > int(l.LimitNum) {
-		return entities[:l.LimitNum], nil
+// Equal reports whether o and other has the same sorting order and name.
+func (o *OrderBy) Equal(other interface{}) bool {
+	if otherOrderBy, ok := other.(*OrderBy); ok {
+		if o == nil && otherOrderBy == nil {
+			return true
+		}
+		if o != nil && otherOrderBy == nil || o == nil && otherOrderBy != nil {
+			return false
+		}
+		return o.Sort == otherOrderBy.Sort &&
+			o.Index.GetMetadata().GetName() == otherOrderBy.Index.GetMetadata().GetName()
 	}
 
-	return entities, nil
-}
-
-func (l *limit) Analyze(s Schema) (Plan, error) {
-	var err error
-	l.Input, err = l.UnresolvedInput.Analyze(s)
-	if err != nil {
-		return nil, err
-	}
-	return l, nil
-}
-
-func (l *limit) Schema() Schema {
-	return l.Input.Schema()
-}
-
-func (l *limit) String() string {
-	return fmt.Sprintf("%s Limit: %d", l.Input.String(), l.LimitNum)
-}
-
-func (l *limit) Children() []Plan {
-	return []Plan{l.Input}
-}
-
-// NewLimit return a limitation expression.
-func NewLimit(input UnresolvedPlan, num uint32) UnresolvedPlan {
-	return &limit{
-		Parent: &Parent{
-			UnresolvedInput: input,
-		},
-		LimitNum: num,
-	}
+	return false
 }
 
-var (
-	_ Plan           = (*offset)(nil)
-	_ UnresolvedPlan = (*offset)(nil)
-)
-
-type offset struct {
-	*Parent
-	offsetNum uint32
+// Strings shows the string represent.
+func (o *OrderBy) String() string {
+	return fmt.Sprintf("OrderBy: %v, sort=%s", o.Index.GetTags(), o.Sort.String())
 }
 
-func (l *offset) Execute(ec executor.StreamExecutionContext) ([]*streamv1.Element, error) {
-	elements, err := l.Parent.Input.(executor.StreamExecutable).Execute(ec)
-	if err != nil {
-		return nil, err
+// ParseOrderBy parses an OrderBy from a Schema.
+func ParseOrderBy(s Schema, indexRuleName string, sort modelv1.Sort) (*OrderBy, error) {
+	if indexRuleName == "" {
+		return &OrderBy{
+			Sort: sort,
+		}, nil
 	}
 
-	if len(elements) > int(l.offsetNum) {
-		return elements[l.offsetNum:], nil
+	defined, indexRule := s.IndexRuleDefined(indexRuleName)
+	if !defined {
+		return nil, errors.Wrap(errIndexNotDefined, indexRuleName)
 	}
 
-	return []*streamv1.Element{}, nil
-}
-
-func (l *offset) Analyze(s Schema) (Plan, error) {
-	var err error
-	l.Input, err = l.UnresolvedInput.Analyze(s)
+	projFieldSpecs, err := s.CreateTagRef(NewTags("", indexRule.GetTags()...))
 	if err != nil {
-		return nil, err
+		return nil, errors.Wrap(errTagNotDefined, indexRuleName)
 	}
-	return l, nil
-}
 
-func (l *offset) Schema() Schema {
-	return l.Input.Schema()
-}
-
-func (l *offset) String() string {
-	return fmt.Sprintf("%s Offset: %d", l.Input.String(), l.offsetNum)
-}
-
-func (l *offset) Children() []Plan {
-	return []Plan{l.Input}
-}
-
-// NewOffset returns a offset expression.
-func NewOffset(input UnresolvedPlan, num uint32) UnresolvedPlan {
-	return &offset{
-		Parent: &Parent{
-			UnresolvedInput: input,
-		},
-		offsetNum: num,
-	}
+	return &OrderBy{
+		Sort:      sort,
+		Index:     indexRule,
+		fieldRefs: projFieldSpecs[0],
+	}, nil
 }
diff --git a/pkg/query/logical/plan_orderby.go b/pkg/query/logical/plan_orderby.go
deleted file mode 100644
index 28071f09..00000000
--- a/pkg/query/logical/plan_orderby.go
+++ /dev/null
@@ -1,101 +0,0 @@
-// Licensed to Apache Software Foundation (ASF) under one or more contributor
-// license agreements. See the NOTICE file distributed with
-// this work for additional information regarding copyright
-// ownership. Apache Software Foundation (ASF) licenses this file to you 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.
-
-package logical
-
-import (
-	"fmt"
-
-	"github.com/pkg/errors"
-
-	databasev1 "github.com/apache/skywalking-banyandb/api/proto/banyandb/database/v1"
-	modelv1 "github.com/apache/skywalking-banyandb/api/proto/banyandb/model/v1"
-)
-
-// UnresolvedOrderBy is unanalyzed sorting expr.
-type UnresolvedOrderBy struct {
-	targetIndexRuleName string
-	sort                modelv1.Sort
-}
-
-// Analyze the UnresolvedOrderBy to get OrderBy result.
-func (u *UnresolvedOrderBy) Analyze(s Schema) (*OrderBy, error) {
-	if u == nil {
-		// return a default orderBy sub-plan
-		return &OrderBy{
-			Sort: modelv1.Sort_SORT_UNSPECIFIED,
-		}, nil
-	}
-
-	if u.targetIndexRuleName == "" {
-		return &OrderBy{
-			Sort: u.sort,
-		}, nil
-	}
-
-	defined, indexRule := s.IndexRuleDefined(u.targetIndexRuleName)
-	if !defined {
-		return nil, errors.Wrap(errIndexNotDefined, u.targetIndexRuleName)
-	}
-
-	projFieldSpecs, err := s.CreateTagRef(NewTags("", indexRule.GetTags()...))
-	if err != nil {
-		return nil, errTagNotDefined
-	}
-
-	return &OrderBy{
-		Sort:      u.sort,
-		Index:     indexRule,
-		fieldRefs: projFieldSpecs[0],
-	}, nil
-}
-
-// OrderBy is the sorting operator.
-type OrderBy struct {
-	Index     *databasev1.IndexRule
-	fieldRefs []*TagRef
-	Sort      modelv1.Sort
-}
-
-// Equal reports whether o and other has the same sorting order and name.
-func (o *OrderBy) Equal(other interface{}) bool {
-	if otherOrderBy, ok := other.(*OrderBy); ok {
-		if o == nil && otherOrderBy == nil {
-			return true
-		}
-		if o != nil && otherOrderBy == nil || o == nil && otherOrderBy != nil {
-			return false
-		}
-		return o.Sort == otherOrderBy.Sort &&
-			o.Index.GetMetadata().GetName() == otherOrderBy.Index.GetMetadata().GetName()
-	}
-
-	return false
-}
-
-// Strings shows the string represent.
-func (o *OrderBy) String() string {
-	return fmt.Sprintf("OrderBy: %v, sort=%s", o.Index.GetTags(), o.Sort.String())
-}
-
-// NewOrderBy return a sorting expr.
-func NewOrderBy(indexRuleName string, sort modelv1.Sort) *UnresolvedOrderBy {
-	return &UnresolvedOrderBy{
-		sort:                sort,
-		targetIndexRuleName: indexRuleName,
-	}
-}
diff --git a/pkg/query/logical/stream/stream_analyzer.go b/pkg/query/logical/stream/stream_analyzer.go
index 466819e4..5972caa1 100644
--- a/pkg/query/logical/stream/stream_analyzer.go
+++ b/pkg/query/logical/stream/stream_analyzer.go
@@ -19,10 +19,12 @@ package stream
 
 import (
 	"context"
+	"fmt"
 
 	commonv1 "github.com/apache/skywalking-banyandb/api/proto/banyandb/common/v1"
 	streamv1 "github.com/apache/skywalking-banyandb/api/proto/banyandb/stream/v1"
 	"github.com/apache/skywalking-banyandb/banyand/stream"
+	"github.com/apache/skywalking-banyandb/pkg/query/executor"
 	"github.com/apache/skywalking-banyandb/pkg/query/logical"
 )
 
@@ -56,25 +58,140 @@ func Analyze(_ context.Context, criteria *streamv1.QueryRequest, metadata *commo
 	// parse fields
 	plan := parseTags(criteria, metadata)
 
-	// parse orderBy
-	queryOrder := criteria.GetOrderBy()
-	if queryOrder != nil {
-		if v, ok := plan.(*unresolvedTagFilter); ok {
-			v.unresolvedOrderBy = logical.NewOrderBy(queryOrder.GetIndexRuleName(), queryOrder.GetSort())
-		}
-	}
-
 	// parse offset
-	plan = logical.NewOffset(plan, criteria.GetOffset())
+	plan = newOffset(plan, criteria.GetOffset())
 
 	// parse limit
 	limitParameter := criteria.GetLimit()
 	if limitParameter == 0 {
 		limitParameter = defaultLimit
 	}
-	plan = logical.NewLimit(plan, limitParameter)
+	plan = newLimit(plan, limitParameter)
+
+	p, err := plan.Analyze(s)
+	if err != nil {
+		return nil, err
+	}
+	rules := []logical.OptimizeRule{
+		logical.NewPushDownOrder(criteria.OrderBy),
+		logical.NewPushDownMaxSize(int(limitParameter + criteria.GetOffset())),
+	}
+	if err := logical.ApplyRules(p, rules...); err != nil {
+		return nil, err
+	}
+	return p, nil
+}
+
+var (
+	_ logical.Plan           = (*limit)(nil)
+	_ logical.UnresolvedPlan = (*limit)(nil)
+)
+
+// Parent refers to a parent node in the execution tree(plan).
+type Parent struct {
+	UnresolvedInput logical.UnresolvedPlan
+	Input           logical.Plan
+}
+
+type limit struct {
+	*Parent
+	LimitNum uint32
+}
+
+func (l *limit) Execute(ec executor.StreamExecutionContext) ([]*streamv1.Element, error) {
+	entities, err := l.Parent.Input.(executor.StreamExecutable).Execute(ec)
+	if err != nil {
+		return nil, err
+	}
+
+	if len(entities) > int(l.LimitNum) {
+		return entities[:l.LimitNum], nil
+	}
+
+	return entities, nil
+}
+
+func (l *limit) Analyze(s logical.Schema) (logical.Plan, error) {
+	var err error
+	l.Input, err = l.UnresolvedInput.Analyze(s)
+	if err != nil {
+		return nil, err
+	}
+	return l, nil
+}
+
+func (l *limit) Schema() logical.Schema {
+	return l.Input.Schema()
+}
+
+func (l *limit) String() string {
+	return fmt.Sprintf("%s Limit: %d", l.Input.String(), l.LimitNum)
+}
+
+func (l *limit) Children() []logical.Plan {
+	return []logical.Plan{l.Input}
+}
+
+func newLimit(input logical.UnresolvedPlan, num uint32) logical.UnresolvedPlan {
+	return &limit{
+		Parent: &Parent{
+			UnresolvedInput: input,
+		},
+		LimitNum: num,
+	}
+}
+
+var (
+	_ logical.Plan           = (*offset)(nil)
+	_ logical.UnresolvedPlan = (*offset)(nil)
+)
+
+type offset struct {
+	*Parent
+	offsetNum uint32
+}
 
-	return plan.Analyze(s)
+func (l *offset) Execute(ec executor.StreamExecutionContext) ([]*streamv1.Element, error) {
+	elements, err := l.Parent.Input.(executor.StreamExecutable).Execute(ec)
+	if err != nil {
+		return nil, err
+	}
+
+	if len(elements) > int(l.offsetNum) {
+		return elements[l.offsetNum:], nil
+	}
+
+	return []*streamv1.Element{}, nil
+}
+
+func (l *offset) Analyze(s logical.Schema) (logical.Plan, error) {
+	var err error
+	l.Input, err = l.UnresolvedInput.Analyze(s)
+	if err != nil {
+		return nil, err
+	}
+	return l, nil
+}
+
+func (l *offset) Schema() logical.Schema {
+	return l.Input.Schema()
+}
+
+func (l *offset) String() string {
+	return fmt.Sprintf("%s Offset: %d", l.Input.String(), l.offsetNum)
+}
+
+func (l *offset) Children() []logical.Plan {
+	return []logical.Plan{l.Input}
+}
+
+func newOffset(input logical.UnresolvedPlan, num uint32) logical.UnresolvedPlan {
+	return &offset{
+		Parent: &Parent{
+			UnresolvedInput: input,
+		},
+		offsetNum: num,
+	}
 }
 
 // parseTags parses the query request to decide which kind of plan should be generated
@@ -86,16 +203,6 @@ func Analyze(_ context.Context, criteria *streamv1.QueryRequest, metadata *commo
 //	we use service_id + service_instance_id + state as the compound sharding keys.
 func parseTags(criteria *streamv1.QueryRequest, metadata *commonv1.Metadata) logical.UnresolvedPlan {
 	timeRange := criteria.GetTimeRange()
-
-	projTags := make([][]*logical.Tag, len(criteria.GetProjection().GetTagFamilies()))
-	for i, tagFamily := range criteria.GetProjection().GetTagFamilies() {
-		var projTagInFamily []*logical.Tag
-		for _, tagName := range tagFamily.GetTags() {
-			projTagInFamily = append(projTagInFamily, logical.NewTag(tagFamily.GetName(), tagName))
-		}
-		projTags[i] = projTagInFamily
-	}
-
 	return tagFilter(timeRange.GetBegin().AsTime(), timeRange.GetEnd().AsTime(), metadata,
-		criteria.Criteria, nil, projTags...)
+		criteria.Criteria, logical.ToTags(criteria.GetProjection()))
 }
diff --git a/pkg/query/logical/stream/stream_plan_indexscan_local.go b/pkg/query/logical/stream/stream_plan_indexscan_local.go
index 00efdb07..d9c9b293 100644
--- a/pkg/query/logical/stream/stream_plan_indexscan_local.go
+++ b/pkg/query/logical/stream/stream_plan_indexscan_local.go
@@ -35,17 +35,30 @@ import (
 	"github.com/apache/skywalking-banyandb/pkg/timestamp"
 )
 
-var _ logical.Plan = (*localIndexScan)(nil)
+var (
+	_ logical.Plan          = (*localIndexScan)(nil)
+	_ logical.Sorter        = (*localIndexScan)(nil)
+	_ logical.VolumeLimiter = (*localIndexScan)(nil)
+)
 
 type localIndexScan struct {
-	schema logical.Schema
-	filter index.Filter
-	*logical.OrderBy
+	schema            logical.Schema
+	filter            index.Filter
+	order             *logical.OrderBy
 	metadata          *commonv1.Metadata
 	l                 *logger.Logger
 	timeRange         timestamp.TimeRange
 	projectionTagRefs [][]*logical.TagRef
 	entities          []tsdb.Entity
+	maxElementSize    int
+}
+
+func (i *localIndexScan) Limit(max int) {
+	i.maxElementSize = max
+}
+
+func (i *localIndexScan) Sort(order *logical.OrderBy) {
+	i.order = order
 }
 
 func (i *localIndexScan) Execute(ec executor.StreamExecutionContext) ([]*streamv1.Element, error) {
@@ -71,13 +84,13 @@ func (i *localIndexScan) Execute(ec executor.StreamExecutionContext) ([]*streamv
 		return nil, nil
 	}
 	var builders []logical.SeekerBuilder
-	if i.Index != nil {
+	if i.order.Index != nil {
 		builders = append(builders, func(builder tsdb.SeekerBuilder) {
-			builder.OrderByIndex(i.Index, i.Sort)
+			builder.OrderByIndex(i.order.Index, i.order.Sort)
 		})
 	} else {
 		builders = append(builders, func(builder tsdb.SeekerBuilder) {
-			builder.OrderByTime(i.Sort)
+			builder.OrderByTime(i.order.Sort)
 		})
 	}
 	if i.filter != nil {
@@ -103,7 +116,7 @@ func (i *localIndexScan) Execute(ec executor.StreamExecutionContext) ([]*streamv
 		return elems, nil
 	}
 
-	it := logical.NewItemIter(iters, i.Sort)
+	it := logical.NewItemIter(iters, i.order.Sort)
 	for it.HasNext() {
 		nextItem := it.Next()
 		tagFamilies, innerErr := logical.ProjectItem(ec, nextItem, i.projectionTagRefs)
@@ -119,14 +132,17 @@ func (i *localIndexScan) Execute(ec executor.StreamExecutionContext) ([]*streamv
 			Timestamp:   timestamppb.New(time.Unix(0, int64(nextItem.Time()))),
 			TagFamilies: tagFamilies,
 		})
+		if len(elems) > i.maxElementSize {
+			break
+		}
 	}
 	return elems, nil
 }
 
 func (i *localIndexScan) String() string {
-	return fmt.Sprintf("IndexScan: startTime=%d,endTime=%d,Metadata{group=%s,name=%s},conditions=%s; projection=%s; orderBy;%s",
+	return fmt.Sprintf("IndexScan: startTime=%d,endTime=%d,Metadata{group=%s,name=%s},conditions=%s; projection=%s; orderBy=%s; limit=%d",
 		i.timeRange.Start.Unix(), i.timeRange.End.Unix(), i.metadata.GetGroup(), i.metadata.GetName(),
-		i.filter, logical.FormatTagRefs(", ", i.projectionTagRefs...), i.OrderBy)
+		i.filter, logical.FormatTagRefs(", ", i.projectionTagRefs...), i.order, i.maxElementSize)
 }
 
 func (i *localIndexScan) Children() []logical.Plan {
diff --git a/pkg/query/logical/stream/stream_plan_tag_filter.go b/pkg/query/logical/stream/stream_plan_tag_filter.go
index 5e8a461d..d74c3654 100644
--- a/pkg/query/logical/stream/stream_plan_tag_filter.go
+++ b/pkg/query/logical/stream/stream_plan_tag_filter.go
@@ -40,12 +40,11 @@ var (
 )
 
 type unresolvedTagFilter struct {
-	startTime         time.Time
-	endTime           time.Time
-	unresolvedOrderBy *logical.UnresolvedOrderBy
-	metadata          *commonv1.Metadata
-	criteria          *modelv1.Criteria
-	projectionTags    [][]*logical.Tag
+	startTime      time.Time
+	endTime        time.Time
+	metadata       *commonv1.Metadata
+	criteria       *modelv1.Criteria
+	projectionTags [][]*logical.Tag
 }
 
 func (uis *unresolvedTagFilter) Analyze(s logical.Schema) (logical.Plan, error) {
@@ -105,15 +104,7 @@ func (uis *unresolvedTagFilter) selectIndexScanner(ctx *analyzeContext) (logical
 			expr:              ctx.globalConditions[1].(logical.LiteralExpr),
 		}, nil
 	}
-
-	// resolve sub-plan with the projected view of streamSchema
-	orderBySubPlan, err := uis.unresolvedOrderBy.Analyze(ctx.s.ProjTags(ctx.projTagsRefs...))
-	if err != nil {
-		return nil, err
-	}
-
 	return &localIndexScan{
-		OrderBy:           orderBySubPlan,
 		timeRange:         timestamp.NewInclusiveTimeRange(uis.startTime, uis.endTime),
 		schema:            ctx.s,
 		projectionTagRefs: ctx.projTagsRefs,
@@ -124,16 +115,14 @@ func (uis *unresolvedTagFilter) selectIndexScanner(ctx *analyzeContext) (logical
 	}, nil
 }
 
-func tagFilter(startTime, endTime time.Time, metadata *commonv1.Metadata, criteria *modelv1.Criteria,
-	orderBy *logical.UnresolvedOrderBy, projection ...[]*logical.Tag,
+func tagFilter(startTime, endTime time.Time, metadata *commonv1.Metadata, criteria *modelv1.Criteria, projection [][]*logical.Tag,
 ) logical.UnresolvedPlan {
 	return &unresolvedTagFilter{
-		unresolvedOrderBy: orderBy,
-		startTime:         startTime,
-		endTime:           endTime,
-		metadata:          metadata,
-		criteria:          criteria,
-		projectionTags:    projection,
+		startTime:      startTime,
+		endTime:        endTime,
+		metadata:       metadata,
+		criteria:       criteria,
+		projectionTags: projection,
 	}
 }
 
diff --git a/test/cases/measure/data/want/bottom.yaml b/test/cases/measure/data/want/bottom.yaml
index 1966657e..760d5a73 100644
--- a/test/cases/measure/data/want/bottom.yaml
+++ b/test/cases/measure/data/want/bottom.yaml
@@ -16,27 +16,27 @@
 # under the License.
 
 dataPoints:
-  - fields:
-    - name: value
+- fields:
+  - name: value
+    value:
+      int:
+        value: "6"
+  tagFamilies:
+  - name: default
+    tags:
+    - key: entity_id
       value:
-        int:
-          value: "100"
-    tagFamilies:
-    - name: default
-      tags:
-      - key: entity_id
-        value:
-          str:
-            value: entity_2
-  - fields:
-    - name: value
+        str:
+          value: entity_2
+- fields:
+  - name: value
+    value:
+      int:
+        value: "6"
+  tagFamilies:
+  - name: default
+    tags:
+    - key: entity_id
       value:
-        int:
-          value: "100"
-    tagFamilies:
-    - name: default
-      tags:
-      - key: entity_id
-        value:
-          str:
-            value: entity_3
\ No newline at end of file
+        str:
+          value: entity_1
\ No newline at end of file
diff --git a/test/cases/measure/data/want/top.yaml b/test/cases/measure/data/want/top.yaml
index 06c543c8..ac6d57cc 100644
--- a/test/cases/measure/data/want/top.yaml
+++ b/test/cases/measure/data/want/top.yaml
@@ -16,27 +16,27 @@
 # under the License.
 
 dataPoints:
-  - fields:
-    - name: value
+- fields:
+  - name: value
+    value:
+      int:
+        value: "8"
+  tagFamilies:
+  - name: default
+    tags:
+    - key: entity_id
       value:
-        int:
-          value: "160"
-    tagFamilies:
-    - name: default
-      tags:
-      - key: entity_id
-        value:
-          str:
-            value: entity_1
-  - fields:
-    - name: value
+        str:
+          value: entity_3
+- fields:
+  - name: value
+    value:
+      int:
+        value: "6"
+  tagFamilies:
+  - name: default
+    tags:
+    - key: entity_id
       value:
-        int:
-          value: "100"
-    tagFamilies:
-    - name: default
-      tags:
-      - key: entity_id
-        value:
-          str:
-            value: entity_3
\ No newline at end of file
+        str:
+          value: entity_2
\ No newline at end of file
diff --git a/ui/LICENSE b/ui/LICENSE
index 4ea63c0c..29234d7d 100644
--- a/ui/LICENSE
+++ b/ui/LICENSE
@@ -16,7 +16,7 @@ The text of each license is also included at licenses/ui-licenses/LICENSE-[proje
 Apache-2.0 licenses
 ========================================================================
 
-    echarts 5.3.3 Apache-2.0
+    echarts 5.4.1 Apache-2.0
 
 ========================================================================
 BSD-3-Clause licenses
@@ -25,13 +25,13 @@ BSD-3-Clause licenses
     normalize-wheel-es 1.2.0 BSD-3-Clause
     source-map 0.6.1 BSD-3-Clause
     source-map-js 1.0.2 BSD-3-Clause
-    zrender 5.3.2 BSD-3-Clause
+    zrender 5.4.1 BSD-3-Clause
 
 ========================================================================
 ISC licenses
 ========================================================================
 
-    anymatch 3.1.2 ISC
+    anymatch 3.1.3 ISC
     glob-parent 5.1.2 ISC
     graceful-fs 4.2.10 ISC
     picocolors 1.0.0 ISC
@@ -40,30 +40,32 @@ ISC licenses
 MIT licenses
 ========================================================================
 
-    @babel/parser 7.19.1 MIT
-    @ctrl/tinycolor 3.4.1 MIT
+    @babel/parser 7.20.7 MIT
+    @ctrl/tinycolor 3.5.0 MIT
     @element-plus/icons-vue 2.0.10 MIT
-    @floating-ui/core 1.0.1 MIT
-    @floating-ui/dom 1.0.1 MIT
+    @floating-ui/core 1.1.0 MIT
+    @floating-ui/dom 1.1.0 MIT
     @popperjs/core 2.11.7 MIT
-    @types/lodash 4.14.185 MIT
+    @types/lodash 4.14.191 MIT
     @types/lodash-es 4.17.6 MIT
-    @types/web-bluetooth 0.0.15 MIT
-    @vue/compiler-core 3.2.39 MIT
-    @vue/compiler-dom 3.2.39 MIT
-    @vue/compiler-sfc 3.2.39 MIT
-    @vue/compiler-ssr 3.2.39 MIT
-    @vue/devtools-api 6.2.1 MIT
-    @vue/reactivity 3.2.39 MIT
-    @vue/reactivity-transform 3.2.39 MIT
-    @vue/runtime-core 3.2.39 MIT
-    @vue/runtime-dom 3.2.39 MIT
-    @vue/server-renderer 3.2.39 MIT
-    @vue/shared 3.2.39 MIT
-    @vueuse/core 9.2.0 MIT
+    @types/web-bluetooth 0.0.16 MIT
+    @vue/compiler-core 3.2.45 MIT
+    @vue/compiler-dom 3.2.45 MIT
+    @vue/compiler-sfc 3.2.45 MIT
+    @vue/compiler-sfc/node_modules/magic-string 0.25.9 MIT
+    @vue/compiler-ssr 3.2.45 MIT
+    @vue/devtools-api 6.4.5 MIT
+    @vue/reactivity 3.2.45 MIT
+    @vue/reactivity-transform 3.2.45 MIT
+    @vue/reactivity-transform/node_modules/magic-string 0.25.9 MIT
+    @vue/runtime-core 3.2.45 MIT
+    @vue/runtime-dom 3.2.45 MIT
+    @vue/server-renderer 3.2.45 MIT
+    @vue/shared 3.2.45 MIT
+    @vueuse/core 9.10.0 MIT
     @vueuse/core/node_modules/vue-demi 0.13.11 MIT
-    @vueuse/metadata 9.2.0 MIT
-    @vueuse/shared 9.2.0 MIT
+    @vueuse/metadata 9.10.0 MIT
+    @vueuse/shared 9.10.0 MIT
     @vueuse/shared/node_modules/vue-demi 0.13.11 MIT
     async-validator 4.2.5 MIT
     asynckit 0.4.0 MIT
@@ -73,15 +75,15 @@ MIT licenses
     chokidar 3.5.3 MIT
     combined-stream 1.0.8 MIT
     csstype 2.6.21 MIT
-    dayjs 1.11.5 MIT
+    dayjs 1.11.7 MIT
     delayed-stream 1.0.0 MIT
-    element-plus 2.2.17 MIT
+    element-plus 2.2.28 MIT
     escape-html 1.0.3 MIT
     estree-walker 2.0.2 MIT
     fill-range 7.0.1 MIT
     follow-redirects 1.15.2 MIT
     form-data 4.0.0 MIT
-    immutable 4.1.0 MIT
+    immutable 4.2.2 MIT
     is-binary-path 2.1.0 MIT
     is-extglob 2.1.1 MIT
     is-glob 4.0.3 MIT
@@ -89,8 +91,7 @@ MIT licenses
     jsonfile 6.1.0 MIT
     lodash 4.17.21 MIT
     lodash-es 4.17.21 MIT
-    lodash-unified 1.0.2 MIT
-    magic-string 0.25.9 MIT
+    lodash-unified 1.0.3 MIT
     memoize-one 6.0.0 MIT
     mime-db 1.52.0 MIT
     mime-types 2.1.35 MIT
@@ -98,13 +99,13 @@ MIT licenses
     nanoid 3.3.4 MIT
     normalize-path 3.0.0 MIT
     picomatch 2.3.1 MIT
-    pinia 2.0.22 MIT
+    pinia 2.0.28 MIT
     pinia/node_modules/vue-demi 0.13.11 MIT
-    postcss 8.4.16 MIT
+    postcss 8.4.21 MIT
     readdirp 3.6.0 MIT
-    sass 1.54.9 MIT
+    sass 1.57.1 MIT
     sourcemap-codec 1.4.8 MIT
     to-regex-range 5.0.1 MIT
     universalify 2.0.0 MIT
-    vue 3.2.39 MIT
-    vue-router 4.1.5 MIT
+    vue 3.2.45 MIT
+    vue-router 4.1.6 MIT