This PR fixes a lock issue that happens while executing
`ALTER LIVE VIEW` query with the `REFRESH` command that
results in a exception. The problem is that lock is currently
being acquired in `InterpreterALterQuery.cpp`
in the `InterpreterAlterQuery::execute()` method and lock
is again being reacquired in `StorageLiveView.cpp` in the
` StorageLiveView::refresh` method. This removes that extra
lock.
Before fix:
```sql
--create table
CREATE TABLE test0 (
c0 UInt64
) ENGINE = MergeTree() PARTITION BY c0 ORDER BY c0;
-- enable experimental_live_view
:) SET allow_experimental_live_view=1
-- create live view;
:) CREATE LIVE VIEW live1 AS SELECT * FROM table0;
-- alter live view results in exception
:) ALTER LIVE VIEW live1 REFRESH;
...
...
Received exception from server (version 20.8.1):
Code: 49. DB::Exception: Received from localhost:9000. DB::Exception: RWLockImpl::getLock(): RWLock is already locked in exclusive mode.
```
After fix:
```sql
:) ALTER LIVE VIEW live1 REFRESH;
ALTER LIVE VIEW live1
REFRESH
Ok.
0 rows in set. Elapsed: 0.016 sec.
```
This commit adds checks in place during table creation
and updates to ensure that we don't allow `CODEC` for
ALIAS (`default_type` column) like:
```sql
CREATE TABLE compression_codec_on_alias
(
`c0` ALIAS c1 CODEC(ZSTD),
`c1` UInt64
)
ENGINE = MergeTree()
PARTITION BY c0
ORDER BY c1;
```
After these safeguards in place, when trying to create/update column
codec, we will get excaptions like this:
```sql
-- create
CREATE TABLE compression_codec_on_alias
(
`c0` ALIAS c1 CODEC(ZSTD),
`c1` UInt64
)
ENGINE = MergeTree()
PARTITION BY c0
ORDER BY c1
Received exception from server (version 20.8.1):
Code: 377. DB::Exception: Received from localhost:9000. DB::Exception: Cannot specify codec for column type ALIAS.
0 rows in set. Elapsed: 0.006 sec.
-- modify
ALTER TABLE compression_codec_on_alias
ADD COLUMN `c3` ALIAS c2 CODEC(ZSTD) AFTER c2
Received exception from server (version 20.8.1):
Code: 377. DB::Exception: Received from localhost:9000. DB::Exception: Cannot specify codec for column type ALIAS.
0 rows in set. Elapsed: 0.005 sec.
```
This PR adds a new setting called `min_index_granularity_bytes`.
If the `index_granularity_bytes` is > 0 and is lesser than the
`min_index_granularity_bytes`, throw an exception inside the
`registerStorageMergeTree.cpp` file.
CurrentMetrics::Increment add amount for specified metric only for the
lifetime of the object, but this is not the intention, since
DistributedFilesToInsert is a gauge and after #10263 it can exit from
the callback (and enter again later, for example after SYSTEM STOP
DISTRIBUTED SEND it will always exit from it, until SYSTEM START
DISTRIBUTED SEND).
So make Increment member of a class (this will also fix possible issues
with substructing value on DROP TABLE).