1#pragma once
2
3#include <common/Types.h>
4
5
6namespace DB
7{
8
9/// What to do if the limit is exceeded.
10enum class OverflowMode
11{
12 THROW = 0, /// Throw exception.
13 BREAK = 1, /// Abort query execution, return what is.
14
15 /** Only for GROUP BY: do not add new rows to the set,
16 * but continue to aggregate for keys that are already in the set.
17 */
18 ANY = 2,
19};
20
21
22struct SizeLimits
23{
24 /// If it is zero, corresponding limit check isn't performed.
25 UInt64 max_rows = 0;
26 UInt64 max_bytes = 0;
27 OverflowMode overflow_mode = OverflowMode::THROW;
28
29 SizeLimits() {}
30 SizeLimits(UInt64 max_rows_, UInt64 max_bytes_, OverflowMode overflow_mode_)
31 : max_rows(max_rows_), max_bytes(max_bytes_), overflow_mode(overflow_mode_) {}
32
33 /// Check limits. If exceeded, return false or throw an exception, depending on overflow_mode.
34 bool check(UInt64 rows, UInt64 bytes, const char * what, int too_many_rows_exception_code, int too_many_bytes_exception_code) const;
35 bool check(UInt64 rows, UInt64 bytes, const char * what, int exception_code) const;
36
37 /// Check limits. No exceptions.
38 bool softCheck(UInt64 rows, UInt64 bytes) const;
39
40 bool hasLimits() const { return max_rows || max_bytes; }
41};
42
43}
44