Repository: ClickHouse/ClickHouse
File: src/Storages/System/StorageSystemTables.cpp (C++)

Code before:
                return;
            }

            NameToNameMap query_parameters_array = getSelectParamters(metadata_snapshot);
            if (!query_parameters_array.empty())
            {
                Array changes;
                for (const auto & [key, value] : query_parameters_array)
                    changes.push_back(Tuple{key, value});
                columns[res_index++]->insert(changes);
            }
            else
                columns[res_index++]->insertDefault();
        }
    }


    void showTablesQuery(MutableColumns & res_columns, bool need_to_check_access_for_tables)
    {
        auto table_details = database->getLightweightTablesIterator(context,
                                /* filter_by_table_name */ {},
                                /* skip_not_loaded */ false);

        const auto access = context->getAccess();
        for (auto & table_detail: table_details)
        {
            size_t src_index = 0;
            size_t res_index = 0;

            if (need_to_check_access_for_tables && !access->isGranted(AccessType::SHOW_TABLES, database_name, table_detail.name))
                continue;

            if (columns_mask[src_index++])
                res_columns[res_index++]->insert(database_name);

            if (columns_mask[src_index++])
                res_columns[res_index++]->insert(table_detail.name);
        }
    }

    Chunk generate() override
    {
        if (done)
            return {};

        MutableColumns res_columns = getPort().getHeader().cloneEmptyColumns();

        const auto access = context->getAccess();
        const bool need_to_check_access_for_databases = !access->isGranted(AccessType::SHOW_TABLES);

        size_t rows_count = 0;

Review comment (performance):
The variables `src_index` and `res_index` are initialized inside the loop but only used for sequential increment. Since the current implementation only handles two columns (database and name) and both are always consecutive, these variables add unnecessary complexity. Consider simplifying the logic or adding a comment explaining why index tracking is needed here.
```suggestion
        const bool need_db = columns_mask[0];
        const bool need_name = columns_mask[1];

        size_t db_res_index = 0;
        size_t name_res_index = 0;

        if (need_db)
        {
            db_res_index = 0;
            if (need_name)
                name_res_index = 1;
        }
        else if (need_name)
        {
            name_res_index = 0;
        }

        const auto access = context->getAccess();
        for (auto & table_detail: table_details)
        {
            if (need_to_check_access_for_tables && !access->isGranted(AccessType::SHOW_TABLES, database_name, table_detail.name))
                continue;

            if (need_db)
                res_columns[db_res_index]->insert(database_name);

            if (need_name)
                res_columns[name_res_index]->insert(table_detail.name);
```

Code after:
        }
    }


    size_t fillTableNamesOnly(MutableColumns & res_columns, bool need_to_check_access_for_tables)
    {
        auto table_details = database->getLightweightTablesIterator(context,
                                /* filter_by_table_name */ {},
                                /* skip_not_loaded */ false);

        size_t count = 0;

        const auto access = context->getAccess();
        for (const auto & table_detail: table_details)
        {
            size_t src_index = 0;
            size_t res_index = 0;

            if (need_to_check_access_for_tables && !access->isGranted(AccessType::SHOW_TABLES, database_name, table_detail.name))
                continue;

            if (columns_mask[src_index++])
                res_columns[res_index++]->insert(database_name);

            if (columns_mask[src_index++])
                res_columns[res_index++]->insert(table_detail.name);

            ++count;
        }
        ++database_idx;
        return count;
    }

    Chunk generate() override
    {
        if (done)
            return {};

        MutableColumns res_columns = getPort().getHeader().cloneEmptyColumns();

        const auto access = context->getAccess();
        const bool need_to_check_access_for_databases = !access->isGranted(AccessType::SHOW_TABLES);

        size_t rows_count = 0;
        while (rows_count < max_block_size)
        {
            if (tables_it && !tables_it->isValid())
                ++database_idx;

            while (database_idx < databases->size() && (!tables_it || !tables_it->isValid()))
            {