云数据库 GAUSSDB-查询改写的Hint:Hint使用准备

时间:2024-11-13 14:46:17

Hint使用准备

为了方便了解hint的使用场景,手册提供了所有查询改写hint的应用示例(请参见Hint使用说明),相关建表语句和环境准备如下:

  • 会话设置:
    SET client_encoding = 'UTF8';
    CREATE SCHEMA rewrite_rule_test;
    SET current_schema = rewrite_rule_test;
    SET enable_codegen= off;
  • 建表语句:
    CREATE TABLE rewrite_rule_hint_t1 (a INT, b INT, c INT, d INT);
    CREATE TABLE rewrite_rule_hint_t2 (a INT, b INT, c INT, d INT);
    CREATE TABLE rewrite_rule_hint_t3 (a INT, b INT, c INT, d INT);
    CREATE TABLE rewrite_rule_hint_t4 (a INT NOT NULL, b INT, c INT, d INT);
    CREATE TABLE rewrite_rule_hint_t5 (slot INTEGER NOT NULL,cid BIGINT NOT NULL,name CHARACTER VARYING NOT NULL) WITH (ORIENTATION = row);
    INSERT INTO rewrite_rule_hint_t5 (slot, cid, name) values(generate_series(1, 10),generate_series(1, 10),'records.storage.state');
    ANALYZE rewrite_rule_hint_t5;
    CREATE TABLE rewrite_rule_hint_customer (
        c_custkey INTEGER NOT NULL,
        c_name CHARACTER VARYING(25) NOT NULL,
        c_address CHARACTER VARYING(40) NOT NULL,
        c_nationkey INTEGER NOT NULL,
        c_phone CHARACTER(15) NOT NULL,
        c_acctbal NUMERIC(15, 2) NOT NULL,
        c_mktsegment CHARACTER(10) NOT NULL,
        c_comment CHARACTER VARYING(117) NOT NULL
    );
    CREATE TABLE rewrite_rule_hint_orders (
        o_orderkey INTEGER NOT NULL,
        o_custkey INTEGER NOT NULL,
        o_orderstatus CHARACTER(1) NOT NULL,
        o_totalprice NUMERIC(15, 2) NOT NULL,
        o_orderdate DATE NOT NULL,
        o_orderpriority CHARACTER(15) NOT NULL,
        o_clerk CHARACTER(15) NOT NULL,
        o_shippriority INTEGER NOT NULL,
        o_comment CHARACTER VARYING(79) NOT NULL
    );
support.huaweicloud.com/centralized-devg-v8-gaussdb/gaussdb-42-0315.html