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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

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)

Working with Flash Session Data in Laravel Working with Flash Session Data in Laravel Mar 12, 2025 pm 05:08 PM

Laravel simplifies handling temporary session data using its intuitive flash methods. This is perfect for displaying brief messages, alerts, or notifications within your application. Data persists only for the subsequent request by default: $request-

cURL in PHP: How to Use the PHP cURL Extension in REST APIs cURL in PHP: How to Use the PHP cURL Extension in REST APIs Mar 14, 2025 am 11:42 AM

The PHP Client URL (cURL) extension is a powerful tool for developers, enabling seamless interaction with remote servers and REST APIs. By leveraging libcurl, a well-respected multi-protocol file transfer library, PHP cURL facilitates efficient execution of various network protocols, including HTTP, HTTPS, and FTP. This extension offers granular control over HTTP requests, supports multiple concurrent operations, and provides built-in security features.

Simplified HTTP Response Mocking in Laravel Tests Simplified HTTP Response Mocking in Laravel Tests Mar 12, 2025 pm 05:09 PM

Laravel provides concise HTTP response simulation syntax, simplifying HTTP interaction testing. This approach significantly reduces code redundancy while making your test simulation more intuitive. The basic implementation provides a variety of response type shortcuts: use Illuminate\Support\Facades\Http; Http::fake([ 'google.com' => 'Hello World', 'github.com' => ['foo' => 'bar'], 'forge.laravel.com' =>

12 Best PHP Chat Scripts on CodeCanyon 12 Best PHP Chat Scripts on CodeCanyon Mar 13, 2025 pm 12:08 PM

Do you want to provide real-time, instant solutions to your customers' most pressing problems? Live chat lets you have real-time conversations with customers and resolve their problems instantly. It allows you to provide faster service to your custom

Explain the concept of late static binding in PHP. Explain the concept of late static binding in PHP. Mar 21, 2025 pm 01:33 PM

Article discusses late static binding (LSB) in PHP, introduced in PHP 5.3, allowing runtime resolution of static method calls for more flexible inheritance.Main issue: LSB vs. traditional polymorphism; LSB's practical applications and potential perfo

Customizing/Extending Frameworks: How to add custom functionality. Customizing/Extending Frameworks: How to add custom functionality. Mar 28, 2025 pm 05:12 PM

The article discusses adding custom functionality to frameworks, focusing on understanding architecture, identifying extension points, and best practices for integration and debugging.

Framework Security Features: Protecting against vulnerabilities. Framework Security Features: Protecting against vulnerabilities. Mar 28, 2025 pm 05:11 PM

Article discusses essential security features in frameworks to protect against vulnerabilities, including input validation, authentication, and regular updates.

See all articles