Accumulate Oracle information on a daily basis

Source: Internet
Author: User
Tags memory usage

For the VARCHAR2 type, we need to make a trade-off in memory usage and efficiency. For the VARCHAR2 (length >=2000) variable, PL/SQL dynamically allocates memory to hold the actual value, but PL/SQL allocates enough memory for the VARCHAR2 (length <2000) variable. So, if we put the same 500-byte value into a VARCHAR2 (2000) and a VARCHAR2 (1999) variable, the latter consumes 1499 bytes of memory.

Exists: The emphasis is on whether to return the result set and not to know what to return, such as:
Select name from student where sex = ' m ' and mark exists (select 1 from grade where ...), as long as
Exists the BOOT clause has a result set return, then exists this condition is set up, we notice that the returned field is always 1, if you change to "Select 2 from Grade where ...", then the returned field is 2, this number is meaningless. So the EXISTS clause does not care what is returned, but rather whether there is a result set returned. By using Exists,oracle, you first check the main query and then run the subquery until it finds the first match, which saves time. When Oracle executes an in subquery, it executes the subquery first and stores the resulting list in an indexed temporary table.  Before executing a subquery, the system first suspends the primary query, and executes the subquery until it has been executed, and then performs the main query after the query is held in the temporary table. In is the appearance and the inner table as a hash connection, and exists is the external loop loop, each loop loop and then query the internal table, has always been considered exists than in the high efficiency of the argument is inaccurate. If the query of two table size is equal, then with in and exists difference is not small, if two tables in a smaller one larger, then the subquery table large with exists, sub-query table small with in;

Try not to use not-in (which calls the subquery) and try to use not exists (which invokes the associated subquery). If any one of the records returned in the subquery contains a null value, the query will not return any records. If the subquery field has a non-empty limit, then you can use not in, and you can connect it with Hasg_aj or merge_aj by prompting it.

If the query statement uses not-in, then a full table scan is performed on the inner surface, and no index is used, whereas the exists of not is still used for indexes on the table. So no matter which table is large, using not exists is faster than not.

Order BY 1 indicates that the selected field is sorted by the first field to order by 1 desc

Accumulate Oracle information on a daily basis

Related Article

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.