KiteSQL icon indicating copy to clipboard operation
KiteSQL copied to clipboard

Feat: Support `TopK` on `Order By ... Limit ...`

Open KKould opened this issue 1 year ago • 3 comments

Feature Request

When OrderBy .. Limit .. exists, the TopK operator will be used

Tips: TopK should also use index

KKould avatar Mar 25 '24 06:03 KKould

It seems that IndexScan will not be used, because the the calculated cost is None(StatisticsMeta file is not found, only Analyze can generate these files, but Analyze may have something wrong)

Analyze table t;
ERROR:  there are more buckets: 100 than elements: 0

crwen avatar Mar 29 '24 14:03 crwen

It seems that IndexScan will not be used, because the the calculated cost is None(StatisticsMeta file is not found, only Analyze can generate these files, but Analyze may have something wrong)

Analyze table t;
ERROR:  there are more buckets: 100 than elements: 0

@crwen

Index arranges data in ascending order, so when OrderBy...ASC, is it possible to remove the Order Operator and convert SeqScan to IndexScan (it cannot be executed if IndexScan has already used other indexes)

https://github.com/KipData/FnckSQL/issues/187#issue-2214992372

Tips: Analyze Table can only be created when the amount of data is greater than 100. Maybe I need to make the information more user-friendly. If you want to use alert table, you can execute benchmark and the internal data will have an index.

KKould avatar Mar 29 '24 14:03 KKould

Tips: IndexScan only makes sense based on large amounts of data. if not, there is not much difference with SeqScan. At the same time, Index data is arranged in ascending order. You can refer to the test cases here to understand the execution of index.

https://github.com/KipData/FnckSQL/blob/main/tests/slt/where_by_index.slt

KKould avatar Mar 29 '24 14:03 KKould