为什么要创建自定义异常?(Why Create Custom Exceptions? [closed])
为什么我们需要在
.NET?
创建自定义异常.NET?
Why do we need to create custom exceptions in
.NET?
原文:https://stackoverflow.com/questions/417428
最满意答案
在回答您的问题之前,请先评论您的SQL函数。
它不会失败,因为语句以错误的顺序执行,但是因为在执行第一个查询之前解析了两个查询。 你得到的错误信息有点像
ERROR: relation "first_table" does not exist [...] CONTEXT: SQL function "doboth" during startup
请注意“启动期间”。
Aswers
您可能会遇到轻微的性能提升,特别是在SQL语句很复杂的情况下,因为PL / pgSQL函数中的SQL语句计划在数据库会话期间被缓存,或者直到它们失效。
如果PL / pgSQL函数缓存了查询计划,但每次都必须计划调用该函数的SQL语句,那么由于执行该函数的开销,实际上可能会更糟糕。
每当使用不同的模式名称调用该函数时,查询计划将失效并且必须重新创建。 因此,如果您为每次调用更改架构名称,您将无法获得任何收益。
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
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.
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.
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.
相关问答
更多-
休眠和多租户数据库在PostgreSQL中使用模式(Hibernate and Multi-Tenant Database using Schemas in PostgreSQL)[2023-10-27]
您可以执行该命令 SET search_path TO customer_schema,public 在相同的连接/会话/事务中尽可能经常地进行。 它只是另一个命令,如SELECT 1; 。 更多的手册在这里 。 当然,你也可以预设每个用户的search_path 。 ALTER ROLE foo SET search_path=foo, public; 如果每个用户或他们中的许多人都有一个与他们的用户名相匹配的模式,那么您可以简单地使用postgresql.conf中的默认设置 : search_pa ... -
在回答您的问题之前,请先评论您的SQL函数。 它不会失败,因为语句以错误的顺序执行,但是因为在执行第一个查询之前解析了两个查询。 你得到的错误信息有点像 ERROR: relation "first_table" does not exist [...] CONTEXT: SQL function "doboth" during startup 请注意“启动期间”。 Aswers 您可能会遇到轻微的性能提升,特别是在SQL语句很复杂的情况下,因为PL / pgSQL函数中的SQL语句计划在数据库会话期 ...
-
在SQL Server中,模式与用户相关联。 每个用户至少有一个默认模式。 您可以将租户与架构关联,这意味着您将拥有映射 租户 - >架构 - >用户 动态构建您的SQL连接字符串并传递与该租户相对应的SQL用户。 通过这种方式,系统会自动指出默认模式,您不必更改Dapper查询,也不必编写动态查询。 注意:不要忘记检查Connection pooling含义。 In SQL Server, the schemas are associated with users. Each user has atlea ...
-
MongoDB中多租户数据库的推荐方法是什么?(What is the recommended approach towards multi-tenant databases in MongoDB?)[2022-01-27]
我有同样的问题要解决,也考虑变体。 由于我有多年创建SaaS多租户应用程序的经验,我也将根据以前的关系数据库经验选择第二个选项。 在进行研究的同时,我在mongodb支持网站上发现了这篇文章: http : //support.mongohq.com/use-cases/multi-tenant.html 这些人声称以任何代价避免第二种选择,据了解,这并不是特别针对mongodb的。 我的印象是,这适用于我研究的大部分NoSQL dbs(CoachDB,Cassandra,CouchBase Server等 ... -
一个可能的解决方案 抽象的问题 是云 ,更具体 - 应用模型 。 我看到它是远程服务器的服务(由大型用户组使用)联网以允许集中数据存储。 我认为SaaS Multitenant Database架构正是您所需要的。 这个问题的答案非常有用。 另外,对于您的情况,我认为一个很好的选择是共享数据库,但是单独的模式。 它允许在同一个DB中容纳多个租户。 哪个租户有自己的架构。 您可以在此演示文稿中找到此解决方案和其 One of possible solution to the abstract problem ...
-
1.我们如何测试每个客户是否根据URL连接到他自己的数据库。 我假设,一旦客户连接,您的应用程序将读取数据库以获取用于呈现页面的数据。 在这种情况下,您只需要将一些唯一数据放入每个客户数据库,然后检查是否显示了正确的数据,最好使用自动化工具。 我们如何在本地系统上模拟不同的域。 像abc.com和xyz.com一样都去了dev机器的IIS。 编辑您正在测试的计算机上的[Windows目录] \ System32 \ drivers \ etc \ hosts文件,并为每个域添加指向dev IIS计算机的条目 ...
-
每个客户查询最好传递给租户。 作为选项,您可以将选定的租户保存在单独的Cookie中,以便在存在此Cookie的情况下知道租户。 另外,请记住,许多网站/应用程序允许用户随时更改语言/租户,而不仅仅是登录。 It is better to pass tenant with each client query. As an option, you may save selected tenant on login in a separate cookie and so you will know tenant ...
-
我已经解决了这个问题。 上面粘贴的路由代码是从教程中复制的,但似乎apartment gem不能与routes.rb文件中的ActiveRecord本机查询一起routes.rb 。 显然,在Page.where()... , Page.where()...调用被映射到public租户而不是请求的租户,因此我已将数据库查询从路由器移动到控制器,而在控制器中,租户转移正在应用正确。 我已经简化了我的路由规则如下,现在它正在工作,我可以通过我的控制器中的slug找到合适的页面: get '/:slug' => ...
-
在Amazon RDS上部署多租户(每个租户都有单独的数据库)(Deploying multi-tenant on Amazon RDS (individual DB for each tenant))[2021-11-25]
数据库是使用标准SQL DDL语句在RDS上创建的 - 而不是API。 例如: 要创建其他数据库,请连接到数据库实例并使用SQL命令CREATE DATABASE 。 http://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_CreateInstance.html Databases are created on RDS using standard SQL DDL statements -- not the API. For example: T ... -
通常, TemplateEngine在Engine初始化期间调用TemplateEngine initialize() 。 但是在这种情况下,未对范围内注入的TemplateResolver进行初始化。 相反,我们将创建/注入已经“初始化”的TemplateResolver 。 我们只是将这一步添加到bean创建中: @Bean(initMethod="initialize") @Scope(value = "tenant", proxyMode = ScopedProxyMode.INTERFACES) ...