Tan-JiaLiang opened a new pull request, #6193:
URL: https://github.com/apache/paimon/pull/6193

   <!-- Please specify the module before the PR name: [core] ... or [flink] ... 
-->
   
   ### Purpose
   
   <!-- Linking this pull request to the issue -->
   The primary-keys is NOT NULL, unique and natural sort by ascending, when 
deletion-vector enabled, the following case can let the TopN convert to limit.
   
   The follow rules can convert TopN to limit.
   1. The order keys order is the same as the primary keys order.
   2. If non-primary key including, the preceding sort keys must be perfect 
matches with the primary keys, then to the non-primary key.
   
   e.g.
   ```sql
   create table T (
     id_0 int not null,
     id_1 int not null,
     name STRING, 
     PRIMARY KEY(id_0, id_1)
   ) WITH (
     'deletion-vector-enabled' = 'true'
   );
   
   -- it can convert to limit the selection from head.
   -- {1,3,5,7,9} == limit from head ==> {1,3,5}
   SELECT * FROM T ORDER BY id_0 LIMIT 3;
   SELECT * FROM T ORDER BY id_0, id_1 LIMIT 3;
   
   -- it can convert to limit the selection from tail.
   -- {1,3,5,7,9} == limit from tail ==> {5,7,9}
   SELECT * FROM T ORDER BY id_0 DESC, id_1 DESC LIMIT 3;
   
   -- it can convert to limit the selection from head.
   -- the `name` order is unnecessary.
   SELECT * FROM T ORDER BY id_0, id_1, name ASC LIMIT 3;
   SELECT * FROM T ORDER BY id_0, id_1, name DESC LIMIT 3;
   ```
   
   <!-- What is the purpose of the change -->
   
   ### Tests
   
   <!-- List UT and IT cases to verify this change -->
   
   ### API and Format
   
   <!-- Does this change affect API or storage format -->
   
   ### Documentation
   
   <!-- Does this change introduce a new feature -->
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to