<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                [TOC] > [參考](https://zhuanlan.zhihu.com/p/355785817) ## 概述 PostgreSQL數據庫的分布式中間件,用以解決PostgreSQL橫向擴展問題,以支持更大的數據量、更大的寫入和查詢性能 ## 場景 ### 多租戶場景 * 高性能支持基于租戶的查詢,高并發下有很好的擴展性; * 由數據庫處理數據分片,對業務透明; * 可以橫向擴容支持更大的數據量; * 橫向擴展并不會損失SQL支持能力; * 高性能支持基于租戶的數據分析; * 很容易通過擴展來支持更多的租戶; * 支持不同粒度租戶的資源隔離; <details> <summary>SQL</summary> ``` CREATE TABLE companies ( id bigint NOT NULL, name text NOT NULL, image_url text, created_at timestamp without time zone NOT NULL, updated_at timestamp without time zone NOT NULL ); CREATE TABLE campaigns ( id bigint NOT NULL, company_id bigint NOT NULL, name text NOT NULL, cost_model text NOT NULL, state text NOT NULL, monthly_budget bigint, blacklisted_site_urls text[], created_at timestamp without time zone NOT NULL, updated_at timestamp without time zone NOT NULL ); CREATE TABLE ads ( id bigint NOT NULL, company_id bigint NOT NULL, campaign_id bigint NOT NULL, name text NOT NULL, image_url text, target_url text, impressions_count bigint DEFAULT 0, clicks_count bigint DEFAULT 0, created_at timestamp without time zone NOT NULL, updated_at timestamp without time zone NOT NULL ); ALTER TABLE companies ADD PRIMARY KEY (id); ALTER TABLE campaigns ADD PRIMARY KEY (id, company_id); ALTER TABLE ads ADD PRIMARY KEY (id, company_id); ``` </details> 通過`create_distributed_table`語句將表設置為分布式表,同時指定`company_id`列為Sharding Key: ``` SELECT create_distributed_table('companies', 'id'); SELECT create_distributed_table('campaigns', 'company_id'); SELECT create_distributed_table('ads', 'company_id'); ``` 可以像普通表一樣,支持增刪改查操作: ``` INSERT INTO companies VALUES (5000, 'New Company', 'https://randomurl/image.png', now(), now()); DELETE FROM campaigns WHERE id = 46 AND company_id = 5; UPDATE campaigns SET monthly_budget = monthly_budget*2 WHERE company_id = 5; SELECT name, cost_model, state, monthly_budget FROM campaigns WHERE company_id = 5 ORDER BY monthly_budget DESC LIMIT 10; ``` ### 實時分析場景 * 隨著數據量增長,仍然能保持亞秒級查詢響應時間; * 支持對實時數據進行實時分析; * 支持多節點并行查詢; * 橫向擴展并不會損失SQL支持能力; * 高并發下有很好的性能擴展性; * 支持PostgreSQL豐富的類型級擴展; <details> <summary>SQL</summary> ``` CREATE TABLE github_events ( event_id bigint, event_type text, event_public boolean, repo_id bigint, payload jsonb, repo jsonb, user_id bigint, org jsonb, created_at timestamp ); CREATE TABLE github_users ( user_id bigint, url text, login text, avatar_url text, gravatar_id text, display_login text ); CREATE INDEX event_type_index ON github_events (event_type); CREATE INDEX payload_index ON github_events USING GIN (payload jsonb_path_ops); ``` </details> 通過`create_distributed_table`語句將表設置為分布式表,,并指定`user_id`列為Sharding Key: ``` SELECT create_distributed_table('github_users', 'user_id'); SELECT create_distributed_table('github_events', 'user_id'); ``` 可以像普通表一樣支持各類分析查詢SQL ``` SELECT count(*) FROM github_users; SELECT date_trunc('minute', created_at) AS minute, sum((payload->>'distinct_size')::int) AS num_commits FROM github_events WHERE event_type = 'PushEvent' GROUP BY minute ORDER BY minute; SELECT login, count(*) FROM github_events ge JOIN github_users gu ON ge.user_id = gu.user_id WHERE event_type = 'CreateEvent' AND payload @> '{"ref_type": "repository"}' GROUP BY login ORDER BY count(*) DESC LIMIT 10; ``` ### Citus不適用的場景 * 單節點PostgreSQL就能滿足的場景,沒有必要分布式; * 離線分析場景,對查詢分析的實時性沒有太高要求; * 不需要支持大量并發用戶的分析場景; * 需要返回大量數據的ETL查詢場景;
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看