ClickHouse/src/Parsers/ASTLiteral.h
Azat Khuzhin 16adcc1666 Reduce memory usage for parsing collections (by using move ctor)
In case you pass array in VALUES section (ValuesBlockInputFormat), it
will be copied after it had been created.
This is not significant if array is small, however if you have huge
enough array, then this can become significant (especially for array of
bool, since for each element will be used Field anyway, and it's size is
56 byte).

Here is a simple reproducer:

    $ curl -sS 'http://127.1:8123/?input_format_values_deduce_templates_of_expressions=0' -d@- <<<"insert into function null('_ Int') values (length([0,$(yes 1, | head -n2000000 | tr -d '\n')1]))"

But note, that there is lots of work (evalute constant expressions from #6781)
after parsing collection, and so total memory usage for query does not
changed a lot (hence - no test).

Signed-off-by: Azat Khuzhin <a.khuzhin@semrush.com>
2022-01-15 21:13:05 +03:00

59 lines
1.8 KiB
C++

#pragma once
#include <Core/Field.h>
#include <Parsers/ASTWithAlias.h>
#include <Parsers/TokenIterator.h>
#include <Common/FieldVisitorDump.h>
#include <optional>
namespace DB
{
/// Literal (atomic) - number, string, NULL
class ASTLiteral : public ASTWithAlias
{
public:
explicit ASTLiteral(Field value_) : value(std::move(value_)) {}
Field value;
/// For ConstantExpressionTemplate
std::optional<TokenIterator> begin;
std::optional<TokenIterator> end;
/*
* The name of the column corresponding to this literal. Only used to
* disambiguate the literal columns with the same display name that are
* created at the expression analyzer stage. In the future, we might want to
* have a full separation between display names and column identifiers. For
* now, this field is effectively just some private EA data.
*/
String unique_column_name;
/// For compatibility reasons in distributed queries,
/// we may need to use legacy column name for tuple literal.
bool use_legacy_column_name_of_tuple = false;
/** Get the text that identifies this element. */
String getID(char delim) const override { return "Literal" + (delim + applyVisitor(FieldVisitorDump(), value)); }
ASTPtr clone() const override { return std::make_shared<ASTLiteral>(*this); }
void updateTreeHashImpl(SipHash & hash_state) const override;
protected:
void formatImplWithoutAlias(const FormatSettings & settings, FormatState &, FormatStateStacked) const override;
void appendColumnNameImpl(WriteBuffer & ostr) const override;
private:
/// Legacy version of 'appendColumnNameImpl'. It differs only with tuple literals.
/// It's only needed to continue working of queries with tuple literals
/// in distributed tables while rolling update.
void appendColumnNameImplLegacy(WriteBuffer & ostr) const;
};
}