[SQL]-Report query efficiency optimization

Source: Internet
Author: User

Background

The system serializes the data object JSON into a database field.
The report module needs to get the value of real-time data objects, and it is time-consuming and inefficient to make numerical judgments in SQL.

Analysis

The inefficiency of the current implementation is mainly the unreasonable design of the program structure.

The SQL bottleneck is as follows, where wordstr is the statistic keyword, and 7 is the string length of wordstr.

sum (len(@colName-len(REPLACE(@colName'wordstr  "))/7)

Solve

Idea 1: Use code to re-implement the statistical function again.
Problem: The program structure changes large amount, the workload is big, temporarily does not adopt.

Idea 2: Optimize data structures and cache statistical variables.
2.1 Add the Statistics Results field, which holds the statistical key values for each row of records.
2.2 Update the data table for all the statistic results fields.
2.3 New trigger, automatically update Insert, update line record changes.
2.4 Update the report SQL and get the results directly from the statistics results.

[SQL]-Report query efficiency optimization

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.