
**Describe the bug**
```
2020.06.30 02:30:04.365074 [ 29070 ] {} <Fatal> BaseDaemon: ########################################
2020.06.30 02:30:04.376366 [ 29070 ] {} <Fatal> BaseDaemon: (version 20.6.1.1, build id: 9B06CBE0F7CE339F) (from thread 21597) (query_id: e7454761-83db-4a1b-8098-886cc7cf3f87) Received signal Segmentation fault (11)
2020.06.30 02:30:04.410422 [ 29070 ] {} <Fatal> BaseDaemon: Address: NULL pointer. Access: read. Unknown si_code.
2020.06.30 02:30:04.431640 [ 29070 ] {} <Fatal> BaseDaemon: Stack trace: 0x1c4272fc 0x1d5d61fd 0x1d5d6898 0x1d5d5bed 0x1cf42f86 0x1d648e97 0x1d8f0efd 0x1d6965bc 0x1d696530 0x1d6964ed 0x1d69649d 0x1d69646d 0x1d6955ce 0x15aef945 0x15aee8b5 0x1d693db5 0x1d6945c7 0x1d69881c 0x1d69877d 0x1d698741 0x1d698712 0x1d69860c 0x1d69859d 0x1d69854d 0x1d69851d 0x1d6976ce 0x15aef945 0x15aee8b5
2020.06.30 02:30:04.500260 [ 29070 ] {} <Fatal> BaseDaemon: 4. /home/avtokmakov/ch/ClickHouse/build_debug/../src/Interpreters/Context.cpp:1952: DB::Context::getApplicationType() const @ 0x1c4272fc in /home/avtokmakov/ch/ClickHouse/build_debug/programs/clickhouse
2020.06.30 02:30:04.590312 [ 29070 ] {} <Fatal> BaseDaemon: 5. /home/avtokmakov/ch/ClickHouse/build_debug/../src/Formats/FormatFactory.cpp:68: DB::getInputFormatSetting(DB::Settings const&, DB::Context const&) @ 0x1d5d61fd in /home/avtokmakov/ch/ClickHouse/build_debug/programs/clickhouse
2020.06.30 02:30:04.671411 [ 29070 ] {} <Fatal> BaseDaemon: 6. /home/avtokmakov/ch/ClickHouse/build_debug/../src/Formats/FormatFactory.cpp:249: DB::FormatFactory::getInputFormat(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, DB::ReadBuffer&, DB::Block const&, DB::Context const&, unsigned long, std::__1::function<void ()>) const @ 0x1d5d6898 in /home/avtokmakov/ch/ClickHouse/build_debug/programs/clickhouse
2020.06.30 02:30:04.748859 [ 29070 ] {} <Fatal> BaseDaemon: 7. /home/avtokmakov/ch/ClickHouse/build_debug/../src/Formats/FormatFactory.cpp:194: DB::FormatFactory::getInput(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, DB::ReadBuffer&, DB::Block const&, DB::Context const&, unsigned long, std::__1::function<void ()>) const @ 0x1d5d5bed in /home/avtokmakov/ch/ClickHouse/build_debug/programs/clickhouse
2020.06.30 02:30:04.862001 [ 29070 ] {} <Fatal> BaseDaemon: 8. /home/avtokmakov/ch/ClickHouse/build_debug/../src/Storages/StorageFile.cpp:314: DB::StorageFileSource::generate() @ 0x1cf42f86 in /home/avtokmakov/ch/ClickHouse/build_debug/programs/clickhouse
2020.06.30 02:30:04.925060 [ 29070 ] {} <Fatal> BaseDaemon: 9. /home/avtokmakov/ch/ClickHouse/build_debug/../src/Processors/ISource.cpp:48: DB::ISource::work() @ 0x1d648e97 in /home/avtokmakov/ch/ClickHouse/build_debug/programs/clickhouse
2020.06.30 02:30:05.018786 [ 29070 ] {} <Fatal> BaseDaemon: 10. /home/avtokmakov/ch/ClickHouse/build_debug/../src/Processors/Sources/SourceWithProgress.cpp:30: DB::SourceWithProgress::work() @ 0x1d8f0efd in /home/avtokmakov/ch/ClickHouse/build_debug/programs/clickhouse
2020.06.30 02:30:05.074849 [ 29070 ] {} <Fatal> BaseDaemon: 11. /home/avtokmakov/ch/ClickHouse/build_debug/../src/Processors/Executors/PipelineExecutor.cpp:155: DB::executeJob(DB::IProcessor*) @ 0x1d6965bc in /home/avtokmakov/ch/ClickHouse/build_debug/programs/clickhouse
2020.06.30 02:30:05.151912 [ 29070 ] {} <Fatal> BaseDaemon: 12. /home/avtokmakov/ch/ClickHouse/build_debug/../src/Processors/Executors/PipelineExecutor.cpp:172: DB::PipelineExecutor::addJob(DB::PipelineExecutor::ExecutionState*)::$_1::operator()() const @ 0x1d696530 in /home/avtokmakov/ch/ClickHouse/build_debug/programs/clickhouse
2020.06.30 02:30:05.220415 [ 29070 ] {} <Fatal> BaseDaemon: 13. /home/avtokmakov/ch/ClickHouse/build_debug/../contrib/libcxx/include/type_traits:3519: decltype(std::__1::forward<DB::PipelineExecutor::addJob(DB::PipelineExecutor::ExecutionState*)::$_1&>(fp)()) std::__1::__invoke<DB::PipelineExecutor::addJob(DB::PipelineExecutor::ExecutionState*)::$_1&>(DB::PipelineExecutor::addJob(DB::PipelineExecutor::ExecutionState*)::$_1&) @ 0x1d6964ed in /home/avtokmakov/ch/ClickHouse/build_debug/programs/clickhouse
2020.06.30 02:30:05.293904 [ 29070 ] {} <Fatal> BaseDaemon: 14. /home/avtokmakov/ch/ClickHouse/build_debug/../contrib/libcxx/include/__functional_base:349: void std::__1::__invoke_void_return_wrapper<void>::__call<DB::PipelineExecutor::addJob(DB::PipelineExecutor::ExecutionState*)::$_1&>(DB::PipelineExecutor::addJob(DB::PipelineExecutor::ExecutionState*)::$_1&) @ 0x1d69649d in /home/avtokmakov/ch/ClickHouse/build_debug/programs/clickhouse
2020.06.30 02:30:05.357185 [ 29070 ] {} <Fatal> BaseDaemon: 15. /home/avtokmakov/ch/ClickHouse/build_debug/../contrib/libcxx/include/functional:1540: std::__1::__function::__alloc_func<DB::PipelineExecutor::addJob(DB::PipelineExecutor::ExecutionState*)::$_1, std::__1::allocator<DB::PipelineExecutor::addJob(DB::PipelineExecutor::ExecutionState*)::$_1>, void ()>::operator()() @ 0x1d69646d in /home/avtokmakov/ch/ClickHouse/build_debug/programs/clickhouse
2020.06.30 02:30:05.410906 [ 29070 ] {} <Fatal> BaseDaemon: 16. /home/avtokmakov/ch/ClickHouse/build_debug/../contrib/libcxx/include/functional:1714: std::__1::__function::__func<DB::PipelineExecutor::addJob(DB::PipelineExecutor::ExecutionState*)::$_1, std::__1::allocator<DB::PipelineExecutor::addJob(DB::PipelineExecutor::ExecutionState*)::$_1>, void ()>::operator()() @ 0x1d6955ce in /home/avtokmakov/ch/ClickHouse/build_debug/programs/clickhouse
2020.06.30 02:30:05.431985 [ 29070 ] {} <Fatal> BaseDaemon: 17. /home/avtokmakov/ch/ClickHouse/build_debug/../contrib/libcxx/include/functional:1867: std::__1::__function::__value_func<void ()>::operator()() const @ 0x15aef945 in /home/avtokmakov/ch/ClickHouse/build_debug/programs/clickhouse
2020.06.30 02:30:05.454815 [ 29070 ] {} <Fatal> BaseDaemon: 18. /home/avtokmakov/ch/ClickHouse/build_debug/../contrib/libcxx/include/functional:2473: std::__1::function<void ()>::operator()() const @ 0x15aee8b5 in /home/avtokmakov/ch/ClickHouse/build_debug/programs/clickhouse
2020.06.30 02:30:05.538482 [ 29070 ] {} <Fatal> BaseDaemon: 19. /home/avtokmakov/ch/ClickHouse/build_debug/../src/Processors/Executors/PipelineExecutor.cpp:633: DB::PipelineExecutor::executeStepImpl(unsigned long, unsigned long, std::__1::atomic<bool>*) @ 0x1d693db5 in /home/avtokmakov/ch/ClickHouse/build_debug/programs/clickhouse
2020.06.30 02:30:05.611525 [ 29070 ] {} <Fatal> BaseDaemon: 20. /home/avtokmakov/ch/ClickHouse/build_debug/../src/Processors/Executors/PipelineExecutor.cpp:546: DB::PipelineExecutor::executeSingleThread(unsigned long, unsigned long) @ 0x1d6945c7 in /home/avtokmakov/ch/ClickHouse/build_debug/programs/clickhouse
2020.06.30 02:30:05.700667 [ 29070 ] {} <Fatal> BaseDaemon: 21. /home/avtokmakov/ch/ClickHouse/build_debug/../src/Processors/Executors/PipelineExecutor.cpp:803: DB::PipelineExecutor::executeImpl(unsigned long)::$_5::operator()() const @ 0x1d69881c in /home/avtokmakov/ch/ClickHouse/build_debug/programs/clickhouse
2020.06.30 02:30:05.764371 [ 29070 ] {} <Fatal> BaseDaemon: 22. /home/avtokmakov/ch/ClickHouse/build_debug/../contrib/libcxx/include/type_traits:3525: decltype(std::__1::forward<DB::PipelineExecutor::executeImpl(unsigned long)::$_5 const&>(fp)()) std::__1::__invoke_constexpr<DB::PipelineExecutor::executeImpl(unsigned long)::$_5 const&>(DB::PipelineExecutor::executeImpl(unsigned long)::$_5 const&) @ 0x1d69877d in /home/avtokmakov/ch/ClickHouse/build_debug/programs/clickhouse
2020.06.30 02:30:05.859223 [ 29070 ] {} <Fatal> BaseDaemon: 23. /home/avtokmakov/ch/ClickHouse/build_debug/../contrib/libcxx/include/tuple:1415: decltype(auto) std::__1::__apply_tuple_impl<DB::PipelineExecutor::executeImpl(unsigned long)::$_5 const&, std::__1::tuple<> const&>(DB::PipelineExecutor::executeImpl(unsigned long)::$_5 const&, std::__1::tuple<> const&, std::__1::__tuple_indices<>) @ 0x1d698741 in /home/avtokmakov/ch/ClickHouse/build_debug/programs/clickhouse
2020.06.30 02:30:05.909173 [ 29070 ] {} <Fatal> BaseDaemon: 24. /home/avtokmakov/ch/ClickHouse/build_debug/../contrib/libcxx/include/tuple:1424: decltype(auto) std::__1::apply<DB::PipelineExecutor::executeImpl(unsigned long)::$_5 const&, std::__1::tuple<> const&>(DB::PipelineExecutor::executeImpl(unsigned long)::$_5 const&, std::__1::tuple<> const&) @ 0x1d698712 in /home/avtokmakov/ch/ClickHouse/build_debug/programs/clickhouse
2020.06.30 02:30:05.956343 [ 29070 ] {} <Fatal> BaseDaemon: 25. /home/avtokmakov/ch/ClickHouse/build_debug/../src/Common/ThreadPool.h:168: ThreadFromGlobalPool::ThreadFromGlobalPool<DB::PipelineExecutor::executeImpl(unsigned long)::$_5>(DB::PipelineExecutor::executeImpl(unsigned long)::$_5&&)::'lambda'()::operator()() const @ 0x1d69860c in /home/avtokmakov/ch/ClickHouse/build_debug/programs/clickhouse
2020.06.30 02:30:06.003016 [ 29070 ] {} <Fatal> BaseDaemon: 26. /home/avtokmakov/ch/ClickHouse/build_debug/../contrib/libcxx/include/type_traits:3519: decltype(std::__1::forward<DB::PipelineExecutor::executeImpl(unsigned long)::$_5>(fp)()) std::__1::__invoke<ThreadFromGlobalPool::ThreadFromGlobalPool<DB::PipelineExecutor::executeImpl(unsigned long)::$_5>(DB::PipelineExecutor::executeImpl(unsigned long)::$_5&&)::'lambda'()&>(DB::PipelineExecutor::executeImpl(unsigned long)::$_5&&) @ 0x1d69859d in /home/avtokmakov/ch/ClickHouse/build_debug/programs/clickhouse
2020.06.30 02:30:06.045811 [ 29070 ] {} <Fatal> BaseDaemon: 27. /home/avtokmakov/ch/ClickHouse/build_debug/../contrib/libcxx/include/__functional_base:349: void std::__1::__invoke_void_return_wrapper<void>::__call<ThreadFromGlobalPool::ThreadFromGlobalPool<DB::PipelineExecutor::executeImpl(unsigned long)::$_5>(DB::PipelineExecutor::executeImpl(unsigned long)::$_5&&)::'lambda'()&>(DB::PipelineExecutor::executeImpl(unsigned long)::$_5&&...) @ 0x1d69854d in /home/avtokmakov/ch/ClickHouse/build_debug/programs/clickhouse
2020.06.30 02:30:06.084320 [ 29070 ] {} <Fatal> BaseDaemon: 28. /home/avtokmakov/ch/ClickHouse/build_debug/../contrib/libcxx/include/functional:1540: std::__1::__function::__alloc_func<ThreadFromGlobalPool::ThreadFromGlobalPool<DB::PipelineExecutor::executeImpl(unsigned long)::$_5>(DB::PipelineExecutor::executeImpl(unsigned long)::$_5&&)::'lambda'(), std::__1::allocator<ThreadFromGlobalPool::ThreadFromGlobalPool<DB::PipelineExecutor::executeImpl(unsigned long)::$_5>(DB::PipelineExecutor::executeImpl(unsigned long)::$_5&&)::'lambda'()>, void ()>::operator()() @ 0x1d69851d in /home/avtokmakov/ch/ClickHouse/build_debug/programs/clickhouse
2020.06.30 02:30:06.121031 [ 29070 ] {} <Fatal> BaseDaemon: 29. /home/avtokmakov/ch/ClickHouse/build_debug/../contrib/libcxx/include/functional:1714: std::__1::__function::__func<ThreadFromGlobalPool::ThreadFromGlobalPool<DB::PipelineExecutor::executeImpl(unsigned long)::$_5>(DB::PipelineExecutor::executeImpl(unsigned long)::$_5&&)::'lambda'(), std::__1::allocator<ThreadFromGlobalPool::ThreadFromGlobalPool<DB::PipelineExecutor::executeImpl(unsigned long)::$_5>(DB::PipelineExecutor::executeImpl(unsigned long)::$_5&&)::'lambda'()>, void ()>::operator()() @ 0x1d6976ce in /home/avtokmakov/ch/ClickHouse/build_debug/programs/clickhouse
2020.06.30 02:30:06.121633 [ 29070 ] {} <Fatal> BaseDaemon: 30. /home/avtokmakov/ch/ClickHouse/build_debug/../contrib/libcxx/include/functional:1867: std::__1::__function::__value_func<void ()>::operator()() const @ 0x15aef945 in /home/avtokmakov/ch/ClickHouse/build_debug/programs/clickhouse
2020.06.30 02:30:06.121985 [ 29070 ] {} <Fatal> BaseDaemon: 31. /home/avtokmakov/ch/ClickHouse/build_debug/../contrib/libcxx/include/functional:2473: std::__1::function<void ()>::operator()() const @ 0x15aee8b5 in /home/avtokmakov/ch/ClickHouse/build_debug/programs/clickhouse
```

**How to reproduce**
Uncomment line in `01193_metadata_loading.sh`. #12045

Seems like some pipes do not hold shared pointer to [`modified_context`](https://github.com/ClickHouse/ClickHouse/blob/c76b4b348101463b345c611becbf9384460ceb7b/src/Storages/StorageMerge.cpp#L158)

#include <Processors/Pipe.h>
#include <IO/WriteHelpers.h>
#include <Processors/Sources/SourceFromInputStream.h>
namespace DB
{
namespace ErrorCodes
{
    extern const int LOGICAL_ERROR;
}
static void checkSingleInput(const IProcessor & transform)