cloudberry icon indicating copy to clipboard operation
cloudberry copied to clipboard

Use FDW to query multiple servers as shards

Open oppenheimer01 opened this issue 2 years ago • 4 comments

This commit mainly meets the needs of users to query multiple clusters as external shards. fdw treats each data source as a whole without knowing its internal structure. It keeps requesters and data sources properly decoupled to maintain generality.

Add a new catalog table pg_foreign_table_seg to enable multiple shards in foreign table. The foreign table should be treated as a shard table with strewn locus. Each QE scanning the foreign should got a shard from pg_foreign_table_seg.

Considering that the size of the computing cluster and the number of shards of the foreign table may be inconsistent. Use flexible gang to generate the same number of scan nodes as foreign table shards.

Considering that the data bandwidth between different data centers is limited, we need to reduce the data transmission of fdw as much as possible. Pushing the execution node down to the remote end as much as possible can reduce data transmission.

If all tables of a subtree are distributed in the same foreign server collection, It can be pushed down. But in mpp-fdw, we should consider if a table only joinning the shared in same foreign server. So a new system attribute gp_foreign_server was add to the foreign table. If the customer add "t1.gp_foreign_server = t2.gp_foreign_server" to join condition. It should be pushed down.

We can only push down the first stage of the two-stage aggregation. Multi-stage aggregation will use some intermediate types. Some of these intermediate types are external types that can be output externally, such as count, min, max, and sum. The intermediate and final types of these types are identical. Others are more complex internal types, such as avg, whose intermediate type is inconsistent with the final type and must be converted using a final function. Since the local node in FDW serves as a standard client to exchange data with the remote server, these internal types cannot be transmitted. So some of the aggregate functions such as "avg" should not be pushed down now.

fix #ISSUE_Number


Change logs

Describe your change clearly, including what problem is being solved or what feature is being added.

If it has some breaking backward or forward compatibility, please clary.

Why are the changes needed?

Describe why the changes are necessary.

Does this PR introduce any user-facing change?

If yes, please clarify the previous behavior and the change this PR proposes.

How was this patch tested?

Please detail how the changes were tested, including manual tests and any relevant unit or integration tests.

Contributor's Checklist

Here are some reminders and checklists before/when submitting your pull request, please check them:

  • [ ] Make sure your Pull Request has a clear title and commit message. You can take git-commit template as a reference.
  • [ ] Sign the Contributor License Agreement as prompted for your first-time contribution(One-time setup).
  • [ ] Learn the coding contribution guide, including our code conventions, workflow and more.
  • [ ] List your communication in the GitHub Issues or Discussions (if has or needed).
  • [ ] Document changes.
  • [ ] Add tests for the change
  • [ ] Pass make installcheck
  • [ ] Pass make -C src/test installcheck-cbdb-parallel
  • [ ] Feel free to request cloudberrydb/dev team for review and approval when your PR is ready🥳

oppenheimer01 avatar Dec 04 '23 10:12 oppenheimer01

CLA assistant check
All committers have signed the CLA.

CLAassistant avatar Dec 04 '23 10:12 CLAassistant

Hi, @oppenheimer01 thanks for your contribution!
Awesome codes and rich description. I'll review this pr soon.

avamingli avatar Dec 05 '23 02:12 avamingli

ic-singlenode-test some errors.

yjhjstz avatar Dec 18 '23 02:12 yjhjstz

ic-singlenode-test some errors.

Got it.

oppenheimer01 avatar Dec 18 '23 06:12 oppenheimer01