Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request (linq): when using Take (or TakeLast), use limit() (or tail) before pivot() #318

Closed
amitrotner opened this issue May 1, 2022 · 2 comments · Fixed by #319
Labels
enhancement New feature or request
Milestone

Comments

@amitrotner
Copy link

Proposed Changes
When using Take or TakeLast operators, translate the query to Flux such as limit() and tail() will be before pivot() to achieve better performance.

A simple experiment conducted locally (see the time difference):

Limit():
Before:
image
After:
image

Tail():
Before:
image

After:
image

@bednar
Copy link
Contributor

bednar commented May 2, 2022

Hi @amitrotner,

thanks for using our client and your suggestion.

Unfortunately we can't do this optimisation as a default behaviour because it doesn't works for all cases. Check out this:

Data
m1 f1=1,f2=2 1
m1 f1=3,f2=4 2
m1 f1=5,f2=6 3
m1 f1=7,f2=8 4
m1 f1=9,f2=10,f3=11 5
m1 f1=12,f2=13,f3=14 6
m1 f1=15,f2=16,f3=17 7
m1 f1=18,f2=19,f3=20 8
Query: select *
from(bucket: "my-bucket") 
	|> range(start: 0)
	|> drop(columns: ["_start", "_stop", "_measurement"])
	|> pivot(rowKey:["_time"], columnKey: ["_field"], valueColumn: "_value")

image

Query: select * limit 2
from(bucket: "my-bucket") 
	|> range(start: 0)
	|> drop(columns: ["_start", "_stop", "_measurement"])
	|> pivot(rowKey:["_time"], columnKey: ["_field"], valueColumn: "_value")
	|> limit(n: 2) 

image

But if we move limit before drop than the results are inconsistent:

from(bucket: "my-bucket") 
	|> range(start: 0)
	|> limit(n: 2) 
	|> drop(columns: ["_start", "_stop", "_measurement"])
	|> pivot(rowKey:["_time"], columnKey: ["_field"], valueColumn: "_value")

image

What do you think about a new option in QueryableOptimizerSettings?

Regards

@amitrotner
Copy link
Author

@bednar
Thanks for your reply.

I see the problem of using my suggestion in this case.
I think a new option in QueryableOptimizerSettings will be good too.

Thanks!

@bednar bednar added the enhancement New feature or request label May 2, 2022
@bednar bednar added this to the 4.2.0 milestone May 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants