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

ISSUES-2553 add offset parameter to numbers #2535

Merged
merged 1 commit into from
Jun 22, 2018

Conversation

zhang2014
Copy link
Contributor

@zhang2014 zhang2014 commented Jun 20, 2018

#2535
I hereby agree to the terms of the CLA available at: https://yandex.ru/legal/cla/?lang=en

@alexey-milovidov alexey-milovidov merged commit f4e7279 into ClickHouse:master Jun 22, 2018
@alexey-milovidov alexey-milovidov self-requested a review June 22, 2018 09:56
@alexey-milovidov
Copy link
Member

You didn't provide any motivation for this change.
So I have to guess, is it any useful.

At first glance, it seems completely useless,
because the user can always write

SELECT number + 10 FROM numbers(123)

instead of

SELECT number FROM numbers(10, 123)

and proposed change will only make query language more heavy.

It's also non obvious (without reading the docs), what does numbers(n, m) means:

  • offset and limit;
  • range begin and end, including end;
  • range begin and end, not including end.

But finally I found at least some possible motivation for your change (but I leave it for you).

@zhang2014
Copy link
Contributor Author

zhang2014 commented Jun 22, 2018

Sorry, I didn't introduce motivation.

At first glance, it seems completely useless,
because the user can always write
SELECT number + 10 FROM numbers(123)
instead of
SELECT number FROM numbers(10, 123)
and proposed change will only make query language more heavy.

You are right, but

  • it's always more efficient
  • SELECT number + 10 AS a, number + 10 AS b ... number + 10 AS n ... is complicated.
  • numbers(10, 123) can always be rewritten as SELECT number FROM system.numbers LIMIT 10,123
  • Maybe we can also support negative numbers : )

@filimonov
Copy link
Contributor

filimonov commented Jun 24, 2018

  1. I doubt tgat performance of numbers table can be a bottleneck in some real scenarios.
  2. you can simplyfy such a selects using WITH clause like
with number + 10 as number2
select number2 as a, number2 as b ...
  1. may be it would be better to introduce range/enumerate table function which will support all data types customizable init value and customizable increment step? Like classic for keyword in programming languages? For example select mondays from enumerate(toDate('2018-08-25'), x -> x <= toDate('2018-12-31'), x -> x + INTERVAL 7 DAYS)

@zhang2014
Copy link
Contributor Author

zhang2014 commented Jun 27, 2018

I doubt tgat performance of numbers table can be a bottleneck in some real scenarios.

Yes, if you use LIMIT m, n you will have unnecessary wait offset, and if you use number + m ... LIMIT n you will have unnecessary operations, like '+'

you can simplyfy such a selects using WITH clause like

That's great

may be it would be better to introduce range/enumerate table function which will support all data types customizable init value and customizable increment step? Like classic for keyword in programming languages? For example select mondays from enumerate(toDate('2018-08-25'), x -> x <= toDate('2018-12-31'), x -> x + INTERVAL 7 DAYS)

Good idea, but the implementation is complicated, but I'll try : )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants