Esta página ainda não está disponível no idioma selecionado. Estamos trabalhando para adicionar mais opções de idiomas. Agradecemos sua compreensão.

Compute
Elastic Cloud Server
Huawei Cloud Flexus
Bare Metal Server
Auto Scaling
Image Management Service
Dedicated Host
FunctionGraph
Cloud Phone Host
Huawei Cloud EulerOS
Networking
Virtual Private Cloud
Elastic IP
Elastic Load Balance
NAT Gateway
Direct Connect
Virtual Private Network
VPC Endpoint
Cloud Connect
Enterprise Router
Enterprise Switch
Global Accelerator
Management & Governance
Cloud Eye
Identity and Access Management
Cloud Trace Service
Resource Formation Service
Tag Management Service
Log Tank Service
Config
OneAccess
Resource Access Manager
Simple Message Notification
Application Performance Management
Application Operations Management
Organizations
Optimization Advisor
IAM Identity Center
Cloud Operations Center
Resource Governance Center
Migration
Server Migration Service
Object Storage Migration Service
Cloud Data Migration
Migration Center
Cloud Ecosystem
KooGallery
Partner Center
User Support
My Account
Billing Center
Cost Center
Resource Center
Enterprise Management
Service Tickets
HUAWEI CLOUD (International) FAQs
ICP Filing
Support Plans
My Credentials
Customer Operation Capabilities
Partner Support Plans
Professional Services
Analytics
MapReduce Service
Data Lake Insight
CloudTable Service
Cloud Search Service
Data Lake Visualization
Data Ingestion Service
GaussDB(DWS)
DataArts Studio
Data Lake Factory
DataArts Lake Formation
IoT
IoT Device Access
Others
Product Pricing Details
System Permissions
Console Quick Start
Common FAQs
Instructions for Associating with a HUAWEI CLOUD Partner
Message Center
Security & Compliance
Security Technologies and Applications
Web Application Firewall
Host Security Service
Cloud Firewall
SecMaster
Anti-DDoS Service
Data Encryption Workshop
Database Security Service
Cloud Bastion Host
Data Security Center
Cloud Certificate Manager
Edge Security
Managed Threat Detection
Blockchain
Blockchain Service
Web3 Node Engine Service
Media Services
Media Processing Center
Video On Demand
Live
SparkRTC
MetaStudio
Storage
Object Storage Service
Elastic Volume Service
Cloud Backup and Recovery
Storage Disaster Recovery Service
Scalable File Service Turbo
Scalable File Service
Volume Backup Service
Cloud Server Backup Service
Data Express Service
Dedicated Distributed Storage Service
Containers
Cloud Container Engine
SoftWare Repository for Container
Application Service Mesh
Ubiquitous Cloud Native Service
Cloud Container Instance
Databases
Relational Database Service
Document Database Service
Data Admin Service
Data Replication Service
GeminiDB
GaussDB
Distributed Database Middleware
Database and Application Migration UGO
TaurusDB
Middleware
Distributed Cache Service
API Gateway
Distributed Message Service for Kafka
Distributed Message Service for RabbitMQ
Distributed Message Service for RocketMQ
Cloud Service Engine
Multi-Site High Availability Service
EventGrid
Dedicated Cloud
Dedicated Computing Cluster
Business Applications
Workspace
ROMA Connect
Message & SMS
Domain Name Service
Edge Data Center Management
Meeting
AI
Face Recognition Service
Graph Engine Service
Content Moderation
Image Recognition
Optical Character Recognition
ModelArts
ImageSearch
Conversational Bot Service
Speech Interaction Service
Huawei HiLens
Video Intelligent Analysis Service
Developer Tools
SDK Developer Guide
API Request Signing Guide
Terraform
Koo Command Line Interface
Content Delivery & Edge Computing
Content Delivery Network
Intelligent EdgeFabric
CloudPond
Intelligent EdgeCloud
Solutions
SAP Cloud
High Performance Computing
Developer Services
ServiceStage
CodeArts
CodeArts PerfTest
CodeArts Req
CodeArts Pipeline
CodeArts Build
CodeArts Deploy
CodeArts Artifact
CodeArts TestPlan
CodeArts Check
CodeArts Repo
Cloud Application Engine
MacroVerse aPaaS
KooMessage
KooPhone
KooDrive

GaussDB(DWS) Stored Procedure Development Specifications

Updated on 2024-12-19 GMT+08:00

Suggestion 4.1: Simplifying Stored Procedures and Avoiding Nesting

NOTE:

Impact of rule violation:

  • The maintenance cost for complex and nested stored procedures is high, making fault locating and recovery time-consuming.

Solution:

  • Avoid using stored procedures altogether or limit their usage to a single layer. Nested stored procedures should be avoided.
  • Create a corresponding log table for the stored procedure design and record information before and after key steps in the log table. Follow the steps below to implement this.

Saving and Viewing Logs

  1. Create a log table.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    CREATE TABLE func_exec_log
    (
    id varchar2(32) default lower(sys_guid()),
    pro_name varchar2(60),
    exec_times int,
    log_date date,
    deal_date date,
    log_mesage text
    );
    

  2. Create a table and import data.

    1
    2
    CREATE TABLE demo_table(data_id int, data_number int);
    INSERT INTO demo_table values(generate_series(1,1000),generate_series(1,1000));
    

  3. Create a service stored procedure.

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    CREATE OR REPLACE FUNCTION demo_table_process(out exe_info text)
    LANGUAGE plpgsql
    AS $$
    declare v_count int;
    pro_result text;
    fun_name   text;
    exec_times   int;
    begin
    fun_name := 'demo_table_process';
    select nvl(max(exec_times), '0') + 1 into exec_times from func_exec_log where pro_name = fun_name;
    -- Insert data into the service table.
    insert into demo_table values (dbms_random.value(1, 1000)::int,generate_series(1, dbms_random.value(10000, 20000)::int));
    get diagnostics v_count = ROW_COUNT;
    exe_info = sysdate || '# step1:insert count:' || v_count || ' rows;';
    -- Delete specified data from a service table.
    delete from demo_table where data_id = dbms_random.value(1, 1000)::int;
    get diagnostics v_count = ROW_COUNT;
    exe_info = exe_info || sysdate || '# step2:delete count:' || v_count || ' rows;';
    -- Update service table data.
    update demo_table set data_number = dbms_random.value(1, 100)::int where data_id = dbms_random.value(1, 1000)::int;
    exe_info = exe_info || sysdate || '# step3:update count:' || sql%rowcount || ' rows';
    -- Record logs either before the entire program ends or after each step completes. You can also create a function specifically for logging purposes.
    insert into func_exec_log(pro_name, exec_times, log_date, deal_date, log_mesage) values (fun_name,exec_times,sysdate,split_part(regexp_split_to_table(exe_info, ';'), '#', 1),split_part(regexp_split_to_table(exe_info, ';'), '#', 2));
    -- EXCEPTION is used to ensure that logs can be properly recorded when the insertion, update, or deletion exits abnormally.
    EXCEPTION
    WHEN OTHERS THEN
    pro_result := exe_info || sysdate || '# exception error message is: ' || sqlerrm;
    insert into func_exec_log(pro_name, exec_times, log_date, deal_date, log_mesage) values(fun_name,exec_times,sysdate,split_part(regexp_split_to_table(pro_result, ';'), '#', 1),split_part(regexp_split_to_table(pro_result, ';'), '#', 2));
    END; $$;
    

  4. Invoke the stored procedure (normal execution).

    1
    SELECT demo_table_process();
    

  5. View the created log table to check the service running status.

    SELECT * FROM func_exec_log ORDER BY log_date desc,deal_date,log_mesage;

  6. Invoke the stored procedure again to construct an execution exception.

    SELECT demo_table_process();  -- Delete the data_number column of demo_table to construct an exception, and then call the stored procedure again.

  7. View the log to check the service running status.

Rule 4.2: Avoiding Non-CREATE DDL Operations in Stored Procedures

NOTE:

Impact of rule violation:

  • A stored procedure is a large transaction. If a non-CREATE DDL operation, especially one with a high lock level, is executed, it can block external access to related tables during the stored procedure's execution window.

Solution:

  • Avoid using non-CREATE DDL operations within stored procedures whenever possible. If there is a necessity to use such operations, carefully assess the duration of the stored procedures and the potential impact of the DDL operations. It is advised to schedule non-CREATE DDL operations during off-peak hours when external access services are less active.

Usamos cookies para aprimorar nosso site e sua experiência. Ao continuar a navegar em nosso site, você aceita nossa política de cookies. Saiba mais

Feedback

Feedback

Feedback

0/500

Selected Content

Submit selected content with the feedback