首页 \ 问答 \ 为什么要创建自定义异常?(Why Create Custom Exceptions? [closed])

为什么要创建自定义异常?(Why Create Custom Exceptions? [closed])

为什么我们需要在.NET?创建自定义异常.NET?


Why do we need to create custom exceptions in .NET?


原文:https://stackoverflow.com/questions/417428
更新时间:2023-04-04 20:04

最满意答案

在回答您的问题之前,请先评论您的SQL函数。

它不会失败,因为语句以错误的顺序执行,但是因为在执行第一个查询之前解析了两个查询。 你得到的错误信息有点像

ERROR:  relation "first_table" does not exist
[...]
CONTEXT:  SQL function "doboth" during startup

请注意“启动期间”。

Aswers

  1. 您可能会遇到轻微的性能提升,特别是在SQL语句很复杂的情况下,因为PL / pgSQL函数中的SQL语句计划在数据库会话期间被缓存,或者直到它们失效。

    如果PL / pgSQL函数缓存了查询计划,但每次都必须计划调用该函数的SQL语句,那么由于执行该函数的开销,实际上可能会更糟糕。

  2. 每当使用不同的模式名称调用该函数时,查询计划将失效并且必须重新创建。 因此,如果您为每次调用更改架构名称,您将无法获得任何收益。

  3. SQL函数不缓存查询计划,因此它们的执行效果不如普通的SQL查询。

但请注意,在函数中缓存简单SQL语句的收益并不是很大。

使用仅作为SQL语句容器的函数,只有这样才能使生活更简单,否则使用纯SQL。

不仅要关注性能设计,还要关注良好的架构和简单的设计。

如果相同的语句不断重复,那么使用预处理语句可能比使用函数获得更多性能。


Before I answer your questions, a remark to your SQL function.

It does not fail because the statements are executed in a wrong order, but because both queries are parsed before the first one is executed. The error message you get is somewhat like

ERROR:  relation "first_table" does not exist
[...]
CONTEXT:  SQL function "doboth" during startup

Note the “during startup”.

Aswers

  1. You may experience a slight performance boost, particularly if the SQL statements are complicated, because the plans of SQL statements in a PL/pgSQL function are cached for the duration of a database session or until they are invalidated.

    If the plan for the query is cached by the PL/pgSQL function, but the SQL statement calling the function has to be planned every time, you might actually be worse of from a performance angle because of the overhead of executing the function.

  2. Whenever you call the function with a different schema name, the query plan will be invalidated and has to be created anew. So if you change the schema name for every invocation, you won't gain anything.

  3. SQL function don't cache query plans, so they don't perform better than the plain SQL query.

Note, however, that the gains from caching simple SQL statements in functions are not tremendous.

Use functions that just act as containers for SQL statements only if it makes life simpler for you, otherwise use plain SQL.

Do not only focus on performance uring design, but on a good architecture and a simple design.

If the same statements keep repeating over and over, you might gain more performance using prepared statements than using functions.

相关问答

更多

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。