Skip to content

Commit

Permalink
*: Remove useless ViewDependencies (#9959)
Browse files Browse the repository at this point in the history
ref #6233

Remove useless `ViewDependencies`
* Remove `PushingToViewsBlockOutputStream`
* Remove `Context::getTCPPort`, `Context::addDependency`, `Context::removeDependency`, `Context::getDependencies`
* Remove `MultiVersion.h`
* Add some comments on `UniversalPageIdFormatImpl.h`, `PageDirectory.cpp`

Signed-off-by: JaySon-Huang <[email protected]>

Co-authored-by: ti-chi-bot[bot] <108142056+ti-chi-bot[bot]@users.noreply.github.com>
  • Loading branch information
JaySon-Huang and ti-chi-bot[bot] authored Mar 7, 2025
1 parent db85ffa commit 3cda2f6
Show file tree
Hide file tree
Showing 23 changed files with 78 additions and 910 deletions.
25 changes: 24 additions & 1 deletion dbms/src/DataStreams/AddingDefaultBlockOutputStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,33 @@
#include <DataStreams/AddingDefaultBlockOutputStream.h>
#include <DataTypes/DataTypeArray.h>
#include <DataTypes/NestedUtils.h>
#include <Interpreters/Context.h>


namespace DB
{
AddingDefaultBlockOutputStream::AddingDefaultBlockOutputStream(
const StoragePtr & storage_,
const ASTPtr & query_ptr_,
const Block & header_,
NamesAndTypesList required_columns_,
const ColumnDefaults & column_defaults_,
const Context & context_)
: storage(storage_)
, header(header_)
, required_columns(required_columns_)
, column_defaults(column_defaults_)
, context(context_)
, query_ptr(query_ptr_)
{
/** Notice
* This is a very important line. At any insertion into the table one of streams should own lock.
* Although now any insertion into the table is done via AddingDefaultBlockOutputStream,
* but it's clear that here is not the best place for this functionality.
*/
addTableLock(storage->lockForShare(context.getCurrentQueryId()));
output = storage->write(query_ptr, context.getSettingsRef());
}

void AddingDefaultBlockOutputStream::write(const Block & block)
{
Expand All @@ -38,7 +61,7 @@ void AddingDefaultBlockOutputStream::write(const Block & block)
{
const auto & elem = res.getByPosition(i);

if (const ColumnArray * array = typeid_cast<const ColumnArray *>(&*elem.column))
if (const auto * array = typeid_cast<const ColumnArray *>(&*elem.column))
{
String offsets_name = Nested::extractTableName(elem.name);
auto & offsets_column = offset_columns[offsets_name];
Expand Down
14 changes: 6 additions & 8 deletions dbms/src/DataStreams/AddingDefaultBlockOutputStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <Interpreters/Context_fwd.h>
#include <Interpreters/evaluateMissingDefaults.h>
#include <Storages/ColumnDefault.h>
#include <Storages/IStorage.h>


namespace DB
Expand All @@ -32,17 +33,12 @@ class AddingDefaultBlockOutputStream : public IBlockOutputStream
{
public:
AddingDefaultBlockOutputStream(
const BlockOutputStreamPtr & output_,
const StoragePtr & storage_,
const ASTPtr & query_ptr_,
const Block & header_,
NamesAndTypesList required_columns_,
const ColumnDefaults & column_defaults_,
const Context & context_)
: output(output_)
, header(header_)
, required_columns(required_columns_)
, column_defaults(column_defaults_)
, context(context_)
{}
const Context & context_);

Block getHeader() const override { return header; }
void write(const Block & block) override;
Expand All @@ -53,11 +49,13 @@ class AddingDefaultBlockOutputStream : public IBlockOutputStream
void writeSuffix() override;

private:
StoragePtr storage;
BlockOutputStreamPtr output;
Block header;
NamesAndTypesList required_columns;
const ColumnDefaults column_defaults;
const Context & context;
ASTPtr query_ptr;
};


Expand Down
61 changes: 0 additions & 61 deletions dbms/src/DataStreams/PushingToViewsBlockOutputStream.cpp

This file was deleted.

71 changes: 0 additions & 71 deletions dbms/src/DataStreams/PushingToViewsBlockOutputStream.h

This file was deleted.

3 changes: 1 addition & 2 deletions dbms/src/Flash/Mpp/tests/gtest_mpp_task_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,12 @@
#include <Flash/Coprocessor/DAGContext.h>
#include <Flash/Mpp/MPPTaskManager.h>
#include <Interpreters/Context.h>
#include <Server/RaftConfigParser.h>
#include <Storages/KVStore/TMTContext.h>
#include <TestUtils/TiFlashTestBasic.h>
#include <TestUtils/TiFlashTestEnv.h>
#include <gtest/gtest.h>

#include "Server/RaftConfigParser.h"

namespace DB
{
namespace tests
Expand Down
84 changes: 8 additions & 76 deletions dbms/src/Interpreters/Context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@

#include <boost/functional/hash/hash.hpp>
#include <pcg_random.hpp>
#include <set>
#include <unordered_map>


Expand Down Expand Up @@ -155,7 +154,6 @@ struct ContextShared
mutable DM::ColumnCacheLongTermPtr column_cache_long_term;
mutable DM::DeltaIndexManagerPtr delta_index_manager; /// Manage the Delta Indies of Segments.
ProcessList process_list; /// Executing queries at the moment.
ViewDependencies view_dependencies; /// Current dependencies
ConfigurationPtr users_config; /// Config with the users, profiles and quotas sections.
BackgroundProcessingPoolPtr background_pool; /// The thread pool for the background work performed by the tables.
BackgroundProcessingPoolPtr
Expand Down Expand Up @@ -755,54 +753,6 @@ void Context::checkDatabaseAccessRightsImpl(const std::string & database_name) c
throw Exception(fmt::format("Access denied to database {}", database_name), ErrorCodes::DATABASE_ACCESS_DENIED);
}

void Context::addDependency(const DatabaseAndTableName & from, const DatabaseAndTableName & where)
{
auto lock = getLock();
checkDatabaseAccessRightsImpl(from.first);
checkDatabaseAccessRightsImpl(where.first);
shared->view_dependencies[from].insert(where);

// Notify table of dependencies change
auto table = tryGetTable(from.first, from.second);
if (table != nullptr)
table->updateDependencies();
}

void Context::removeDependency(const DatabaseAndTableName & from, const DatabaseAndTableName & where)
{
auto lock = getLock();
checkDatabaseAccessRightsImpl(from.first);
checkDatabaseAccessRightsImpl(where.first);
shared->view_dependencies[from].erase(where);

// Notify table of dependencies change
auto table = tryGetTable(from.first, from.second);
if (table != nullptr)
table->updateDependencies();
}

Dependencies Context::getDependencies(const String & database_name, const String & table_name) const
{
auto lock = getLock();

String db = resolveDatabase(database_name, current_database);

if (database_name.empty() && tryGetExternalTable(table_name))
{
/// Table is temporary. Access granted.
}
else
{
checkDatabaseAccessRightsImpl(db);
}

auto iter = shared->view_dependencies.find(DatabaseAndTableName(db, table_name));
if (iter == shared->view_dependencies.end())
return {};

return Dependencies(iter->second.begin(), iter->second.end());
}

bool Context::isTableExist(const String & database_name, const String & table_name) const
{
auto lock = getLock();
Expand Down Expand Up @@ -1147,25 +1097,15 @@ void Context::setSettings(const Settings & settings_)

void Context::setSetting(const String & name, const Field & value)
{
if (name == "profile")
{
auto lock = getLock();
settings.setProfile(value.safeGet<String>(), *shared->users_config);
}
else
settings.set(name, value);
assert(name != "profile");
settings.set(name, value);
}


void Context::setSetting(const String & name, const std::string & value)
{
if (name == "profile")
{
auto lock = getLock();
settings.setProfile(value, *shared->users_config);
}
else
settings.set(name, value);
assert(name != "profile");
settings.set(name, value);
}


Expand Down Expand Up @@ -1971,15 +1911,6 @@ SharedContextDisaggPtr Context::getSharedContextDisagg() const
return shared->ctx_disagg;
}

UInt16 Context::getTCPPort() const
{
auto lock = getLock();

auto & config = getConfigRef();
return config.getInt("tcp_port");
}


void Context::initializeSystemLogs()
{
auto lock = getLock();
Expand Down Expand Up @@ -2070,7 +2001,8 @@ void Context::shutdown()
void Context::setDefaultProfiles()
{
shared->default_profile_name = "default";
setSetting("profile", shared->default_profile_name);
auto lock = getLock();
settings.setProfile(shared->default_profile_name, *shared->users_config);
is_config_loaded = true;
}

Expand Down Expand Up @@ -2205,12 +2137,12 @@ void Context::initRegionBlocklist(const std::unordered_set<RegionID> & region_id
auto lock = getLock();
shared->region_blocklist = region_ids;
}
bool Context::isRegionInBlocklist(const RegionID region_id)
bool Context::isRegionInBlocklist(const RegionID region_id) const
{
auto lock = getLock();
return shared->region_blocklist.count(region_id) > 0;
}
bool Context::isRegionsContainsInBlocklist(const std::vector<RegionID> & regions)
bool Context::isRegionsContainsInBlocklist(const std::vector<RegionID> & regions) const
{
auto lock = getLock();
for (const auto region : regions)
Expand Down
Loading

0 comments on commit 3cda2f6

Please sign in to comment.