Paging optimization example

Source: Internet
Author: User

The NDB engine requires orderby every time to maintain the order.


User_id is the index Column



Original code


Select

SC _user_id userid,

SC _user_nm username,

SC _user_sex usersex,

SC _user_real_name userrealname,

SC _mobile_no mobileno,

Email,

Scl_register_dts registerdts,

Scl_account_balance accountbalance,

Scl_recharge_amt rechargeamt,

Scl_invest_amt investamt,

Scx_redemption_amt redemptionamt,

Scx_freeze_amt freezeamt,

Scx_freeze_amtf withdrawamt,

Create_dtss createdts,

Update_dtstime updatedts

From tbl_custdserv_7user

Where update_dtstime> = Concat ('20160301', '20160301 ')

Order by SC _user_nm

Limit 35950,50;


Execution time: 7.45 seconds




========================================================== ======================================

Optimized Code


Select

A. SC _user_id userid,

A. SC _user_nm username,

A. SC _user_sex usersex,

A. SC _user_real_name userrealname,

A. SC _mobile_no mobileno,

A. email,

A. scl_register_dts registerdts,

A. scl_account_balance accountbalance,

A. scl_recharge_amt rechargeamt,

A. scl_invest_amt investamt,

A. scx_redemption_amt redemptionamt,

A. scx_freeze_amt freezeamt,

A. scx_freeze_amtf withdrawamt,

A. create_dtss createdts,

A. update_dtstime updatedts

From tbl_custdserv_7user


Join

 

(Select

SC _user_id,

SC _user_nm

From tbl_custdserv_7user

Where update_dtstime> = Concat ('20160301', '20160301 ')

Order by SC _user_nm

Limit 35950,50) B


On a. SC _user_id = B. user_id


Execution time: 0.2 seconds




Failed to try on a. SC _user_nm = B. SC _user_nm


This article from the "deep mountains with dba" blog, please be sure to keep this source http://19801021.blog.51cto.com/7262596/1567147

Paging optimization example

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.