Table of Contents
回复讨论(解决方案)
Home Backend Development PHP Tutorial union all效率低下,该用存储过程、视图、临时表哪种方法来解决?

union all效率低下,该用存储过程、视图、临时表哪种方法来解决?

Jun 23, 2016 pm 02:04 PM

union all效率低下,大概union all数十张表,单表select仅需0.0003-0.002秒,但union all后需要0.6秒左右
想改善下效率

这种情况该用存储过程、视图、临时表哪种方法来解决?


回复讨论(解决方案)

很明显,你的数据组织的不合理

很明显,你的数据组织的不合理

难道从来不会有这种情况发生吗

组织合理就没有这种情况

你把同类数据垂直分配在数十个表中,就是不合理

组织合理就没有这种情况

你把同类数据垂直分配在数十个表中,就是不合理

这些表的结构不完全相同的。当时就是考虑到放在一张表会复杂。所以就分开了。不过后来发现要汇总时,问题就来了。

大家有没有好的办法。之前建立的那些表已经应用到一些功能上了。现在改也太大工程了。

你能说一下你的那些表的结构吗?
既然并不相同,那么叠加在一起的意义何在?

你能说一下你的那些表的结构吗?
既然并不相同,那么叠加在一起的意义何在?
我刚刚查了一下,7个表,分别是
1.销售凭证、红字销售凭证
2.采购凭证、红字采购凭证
3.收款凭证、付款凭证、转账凭证。
  
其中1组和2组结构是一样的,1组和2组只有一个字段不同。
3组中的收款凭证和付款凭证也是只有一字段不同,转账凭证的结构则是被收款凭证和付款凭证所包含。

补充一下,1组和2组各自内部的表结构是一样的。1组和2组之间只有一个字段不同。

1组和2组不同的字段是,
1组有‘销售单号、客户编码‘。
2组有 ’采购单号、供应商编码’。

1组和2组的表结构是这样,能合并成一个表吗?

数据量有多大啊?要达到分表的情况下了。分表的话,这种水平分也不合理吧。

你用 union 这不就对了!
这7个表是平行的,就算要连接也只能是 join

数据量有多大啊?要达到分表的情况下了。分表的话,这种水平分也不合理吧。

其实它们都是描述不同的东西。所以才分表的。

1.销售凭证、红字销售凭证
2.采购凭证、红字采购凭证
3.收款凭证、付款凭证、转账凭证。




你用 union 这不就对了!
这7个表是平行的,就算要连接也只能是 join

将1、2组表结构合并,3组表结构合并,这样合理么。

不必了吧?你不是说已经应用到一些功能上了吗?

不必了吧?你不是说已经应用到一些功能上了吗?

就是各自的一个增删查改的功能。我不知道这样设计,以后会不会有其它不好处理的地方出现。

愿意的话,你可以描述一下业务流程

刚刚那7个表是接下来要做的几个功能的数据来源。

比如,有一个日记账的功能,这个功能就是要从刚刚那7个表中的记录搜索有“银行存款和现金”这两个科目存在的明细记录。要把有这两个存的的明细都抽出来,然后汇总显示。

第二个,明细账功能,这个也是要从刚刚那7个表中搜索除了“银行存款和现金”以外的所有科目存在的明细记录,汇总显示。

第三个,科目汇总表,这个是在一定时间范围内,所有凭证按科目汇总。

第四个,总分类账,就是显示每个科目发生的所有明细记录。

可能描述的不是很好。请见谅。

union all 之后还做了order之类? 要不不该差这么大啊

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1663
14
PHP Tutorial
1263
29
C# Tutorial
1236
24
Explain different error types in PHP (Notice, Warning, Fatal Error, Parse Error). Explain different error types in PHP (Notice, Warning, Fatal Error, Parse Error). Apr 08, 2025 am 12:03 AM

There are four main error types in PHP: 1.Notice: the slightest, will not interrupt the program, such as accessing undefined variables; 2. Warning: serious than Notice, will not terminate the program, such as containing no files; 3. FatalError: the most serious, will terminate the program, such as calling no function; 4. ParseError: syntax error, will prevent the program from being executed, such as forgetting to add the end tag.

Explain secure password hashing in PHP (e.g., password_hash, password_verify). Why not use MD5 or SHA1? Explain secure password hashing in PHP (e.g., password_hash, password_verify). Why not use MD5 or SHA1? Apr 17, 2025 am 12:06 AM

In PHP, password_hash and password_verify functions should be used to implement secure password hashing, and MD5 or SHA1 should not be used. 1) password_hash generates a hash containing salt values ​​to enhance security. 2) Password_verify verify password and ensure security by comparing hash values. 3) MD5 and SHA1 are vulnerable and lack salt values, and are not suitable for modern password security.

PHP and Python: Comparing Two Popular Programming Languages PHP and Python: Comparing Two Popular Programming Languages Apr 14, 2025 am 12:13 AM

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

PHP in Action: Real-World Examples and Applications PHP in Action: Real-World Examples and Applications Apr 14, 2025 am 12:19 AM

PHP is widely used in e-commerce, content management systems and API development. 1) E-commerce: used for shopping cart function and payment processing. 2) Content management system: used for dynamic content generation and user management. 3) API development: used for RESTful API development and API security. Through performance optimization and best practices, the efficiency and maintainability of PHP applications are improved.

What are HTTP request methods (GET, POST, PUT, DELETE, etc.) and when should each be used? What are HTTP request methods (GET, POST, PUT, DELETE, etc.) and when should each be used? Apr 09, 2025 am 12:09 AM

HTTP request methods include GET, POST, PUT and DELETE, which are used to obtain, submit, update and delete resources respectively. 1. The GET method is used to obtain resources and is suitable for read operations. 2. The POST method is used to submit data and is often used to create new resources. 3. The PUT method is used to update resources and is suitable for complete updates. 4. The DELETE method is used to delete resources and is suitable for deletion operations.

PHP: A Key Language for Web Development PHP: A Key Language for Web Development Apr 13, 2025 am 12:08 AM

PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7

Explain the difference between self::, parent::, and static:: in PHP OOP. Explain the difference between self::, parent::, and static:: in PHP OOP. Apr 09, 2025 am 12:04 AM

In PHPOOP, self:: refers to the current class, parent:: refers to the parent class, static:: is used for late static binding. 1.self:: is used for static method and constant calls, but does not support late static binding. 2.parent:: is used for subclasses to call parent class methods, and private methods cannot be accessed. 3.static:: supports late static binding, suitable for inheritance and polymorphism, but may affect the readability of the code.

How does PHP handle file uploads securely? How does PHP handle file uploads securely? Apr 10, 2025 am 09:37 AM

PHP handles file uploads through the $\_FILES variable. The methods to ensure security include: 1. Check upload errors, 2. Verify file type and size, 3. Prevent file overwriting, 4. Move files to a permanent storage location.

See all articles