Default database select sorting

Source: Internet
Author: User


The default sorting of database select oracle does not sort the results returned by statements without order by. oracle reads data in the physical storage order. Because rowid is the address of each row of data, it sometimes looks like it is sorted by rowid. However, this order may be disrupted. After the table data is deleted, the rowid will be occupied by the newly inserted data. Therefore, the result of a query without order by may also be messy. How can MySQL sort the Select statement without adding "Order? * Do not rely on the default sorting of MySQL * if you want to sort, Order By * group by is always added to impose Order, the default sorting of MySQL Select in MyISAM table is displayed in the physical storage order at www.2cto.com. (No additional sorting). That is to say, SELECT * FROM tbl-will generate a "Table scan ". If the table is not deleted, replaced, or updated, the sequence of insertion is displayed. In the same case, InnoDB tables are arranged in the order of primary keys. However, this is unreliable. Potential rules. When "Select" is not added with "Order by", MySQL will try to return data in the fastest way possible (the actual MySQL method is not fast. Because primary keys and indexes are faster in most cases (in the Cache), the returned data may be output in the order of primary keys and indexes. In this case, the data is not actually sorted, it is mainly because the primary key and index are stored in the memory, so the continuous output may be a sequence. In some cases, data that consumes the shortest track time on the hard disk will be returned first. If you only query a single table, it is regular under special circumstances. Www.2cto.com concluded that "Order By is to be added". We must add order by to the paging logic by default. If the order By field has duplicate values, we must specify the second sorting field, if there are duplicate values in the second sorting field, you must specify more fields until all sorting fields can specify the unique order.
 

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.