SQL CASE语句与编程语言中的条件语句(SQL CASE Statement Versus Conditional Statements In Programming Language)
我在工作中经历了一些旧的存储过程并且经常遇到
CASE MyColumn WHEN 'Y' THEN 'Yes' WHEN 'N' THEN 'No' ELSE 'Unknown' END
如果这不是一个单词,而是一个颜色,那就更糟了。
CASE MyColumn WHEN 'Y' THEN 'style="background-color:pink"' ELSE '' END
这样做的原因是旧的ASP 1页面,其中所有内容都必须内联,但由于它是如此庞大的系统,因此无法跟上更新所有页面的步伐。
任何人都可以提供任何有效的证据证明对条件语句使用SQL查询超过了其他语言(如C#或Java)吗? 这是速度的好习惯吗? 是否应该返回普通值并且表示层决定应该做什么?
I'm going through some old stored procedures at work and constantly come across
CASE MyColumn WHEN 'Y' THEN 'Yes' WHEN 'N' THEN 'No' ELSE 'Unknown' END
It gets even worse when this is tied not to a word, but instead a colour.
CASE MyColumn WHEN 'Y' THEN 'style="background-color:pink"' ELSE '' END
The reason this was done was for older ASP 1 pages where everything had to be done inline, but as it's such a large system it's impossible to keep up with updating all the pages.
Can anyone give any valid evidence that using a SQL query for conditional statements surpasses that in other languages such as C# or Java? Is this good practice for speed? Should the plain value be returned and the presentation layer decide what should be done?
原文:https://stackoverflow.com/questions/487770
最满意答案
我在CentOS 6.3上遇到了同样的问题。 问题最终是EPEL yum repo中没有collectd-dbi rpm。 你必须从其他地方获得dbi插件。
检查您已安装的collectd版本
$ yum info collectd
这就是结果对我而言
Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile Installed Packages Name : collectd Arch : x86_64 Version : 4.10.7 Release : 1.el6 Size : 1.3 M Repo : installed From repo : epel
您可以尝试在网络上搜索某人建立的RPM,但在我的情况下,我找不到我的确切版本。 因此,我认为唯一的解决方案是从源代码编译collectd。 以下是我编译collectd并安装dbi插件的步骤
克隆collectd仓库并签出您已安装的版本
git clone https://github.com/collectd/collectd.git cd collectd/ git checkout collectd-4.10.7
安装依赖项以编译collectd。 以下是我需要安装以进行编译的所有内容,但您可能需要安装更多内容。 注意,libdbi-devel是必需的。 如果没有安装,那么在运行configure脚本时,dbi插件将不会启用而不会被编译。
sudo yum install autoconf automake flex ppl cloog-ppl cpp libgomp mpfr glibc-devel glibc-headers kernel-headers gcc libtool libtool-ltdl libtool-ltdl-devel libgcrypt-devel libgpg-error-devel libdbi libdbi-devel bison byacc db4-cxx db4-devel gdbm-devel perl-ExtUtils-MakeMaker perl-ExtUtils-ParseXS perl-Test-Harness perl-devel
运行以下命令并确保没有错误
./build.sh && ./configure && make
假设编译没有问题,那么你应该编译dbi插件。 你可以在
src/.libs/dbi.so
找到它检查是否已安装所有链接库
$ ldd src/.libs/dbi.so linux-vdso.so.1 => (0x00007fff109ff000) libdbi.so.0 => /usr/lib64/libdbi.so.0 (0x00007fca4a53c000) libdl.so.2 => /lib64/libdl.so.2 (0x00007fca4a338000) libc.so.6 => /lib64/libc.so.6 (0x00007fca49fa3000) libm.so.6 => /lib64/libm.so.6 (0x00007fca49d1f000) /lib64/ld-linux-x86-64.so.2 (0x00007fca4a95a000)
如果看起来不错,可以将dbi.so共享对象安装到collectd lib目录,如下所示:
sudo install -o root -g root src/.libs/dbi.so /usr/lib64/collectd/
您现在应该可以重新启动collectd并加载dbi库
$ sudo service collectd restart Stopping collectd: [ OK ] Starting collectd: [ OK ]
希望有所帮助
I had the same issue on CentOS 6.3. The problem ended up being that there is no collectd-dbi rpm in the EPEL yum repo. You'll have to get the dbi plugin from elsewhere.
Check which version of collectd you have installed
$ yum info collectd
This is what the results were for me
Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile Installed Packages Name : collectd Arch : x86_64 Version : 4.10.7 Release : 1.el6 Size : 1.3 M Repo : installed From repo : epel
You can try searching around the web for an RPM that someone built, but in my case I couldn't find one for my exact version. Because of this, I think the only solution is to compile collectd from source. The following are the steps I took to compile collectd and get the dbi plugin installed
Clone the collectd repo and checkout the version that you already have installed
git clone https://github.com/collectd/collectd.git cd collectd/ git checkout collectd-4.10.7
Install dependencies to compile collectd. Below is everything I needed to install for compiling this, but there might be more you need to install. Note, libdbi-devel is required. If it doesn't get installed, then when running configure script, the dbi plugin will not enabled and not compiled.
sudo yum install autoconf automake flex ppl cloog-ppl cpp libgomp mpfr glibc-devel glibc-headers kernel-headers gcc libtool libtool-ltdl libtool-ltdl-devel libgcrypt-devel libgpg-error-devel libdbi libdbi-devel bison byacc db4-cxx db4-devel gdbm-devel perl-ExtUtils-MakeMaker perl-ExtUtils-ParseXS perl-Test-Harness perl-devel
Run the following and make sure there are no errors
./build.sh && ./configure && make
Assuming there were no issues compiling, then you should have the dbi plugin compiled. You can find it in
src/.libs/dbi.so
Check that you have all the linked libraries installed
$ ldd src/.libs/dbi.so linux-vdso.so.1 => (0x00007fff109ff000) libdbi.so.0 => /usr/lib64/libdbi.so.0 (0x00007fca4a53c000) libdl.so.2 => /lib64/libdl.so.2 (0x00007fca4a338000) libc.so.6 => /lib64/libc.so.6 (0x00007fca49fa3000) libm.so.6 => /lib64/libm.so.6 (0x00007fca49d1f000) /lib64/ld-linux-x86-64.so.2 (0x00007fca4a95a000)
If that looks good, you can install the dbi.so shared object to the collectd lib directory like so:
sudo install -o root -g root src/.libs/dbi.so /usr/lib64/collectd/
You should now be able to restart collectd and have the dbi library loaded
$ sudo service collectd restart Stopping collectd: [ OK ] Starting collectd: [ OK ]
Hope that helps
相关问答
更多-
由于selinux,我遇到了类似的错误。 您可以按照文档允许collectd发送指标https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/6/html/Security-Enhanced_Linux/sect-Security-Enhanced_Linux-Fixing_Problems-Allowing_Access_audit2allow.html 对我来说,步骤是遵循命令。 audit2allow -a ...
-
我在CentOS 6.3上遇到了同样的问题。 问题最终是EPEL yum repo中没有collectd-dbi rpm。 你必须从其他地方获得dbi插件。 检查您已安装的collectd版本 $ yum info collectd 这就是结果对我而言 Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile Installed Packages Name : collectd Arch : ...
-
struct curl_slist * curl_list = NULL; curl_list = curl_slist_append(curl_list, header); curl_easy_setopt(curl, CURLOPT_HTTPHEADER, curl_list); struct curl_slist *curl_list = NULL; curl_list = curl_slist_append(curl_list, header); curl_easy_s ...
-
munin-run切换用户 。 默认用户是nobody 。 该用户可能无权读取该文件。 该脚本必须以足够的权限运行,通常以root身份运行,因为它切换到munin-node的默认用户(通常是“nobody”)或任何专门配置为运行给定插件的用户。 检查munin-run --debug用户是什么,并检查用户是否可以读取/usr/local/lib64/perl5/DBI.pm 。 munin-run switches users. The default user is nobody. That user p ...
-
以下是github的回答。 感谢您报告此事。 但是,它的行为和预期的工作原理是:只能有一个ExcludeRegex设置,如果有更多,则后面的设置将覆盖以前的设置。 您可以使用正则表达式OR运算符|来实现您的目标: ExcludeRegex "HTTP/1..\" 404|HTTP/1..\" 404" 或者,更短: ExcludeRegex "HTTP/1..\" (404|499)" 最好的祝福, The following is an answer from github. thank you fo ...
-
Collectd - Perl / Python插件 - 注册功能不起作用(Collectd - Perl/Python plugin - registration functions not working)[2022-08-05]
如果可以,请发布您的配置。 文档说LoadPlugin配置在collectd.conf文件中(在您的日志文件中,这似乎不重要)。 将你的foobar.pm模块放在/path/to/perl/plugins/Collectd/Plugins/FoorBar.pm将它与你指定的/path/to/perl/plugins/Collectd/Plugins/FoorBar.pm相匹配...(匹配插件和插件pm文件名称的情况)。 LoadPlugin perl # ...Includ ... -
https://github.com/collectd/collectd/tree/master/bindings/java/org/collectd/java 顺便说一句,我发现另一个插件JMXMemory.java更直接,因此是CollectD Java插件的一个更好的例子。 https://github.com/collectd/collectd/tree/master/bindings/java/org/collectd/java BTW, I found another plugin, JMXMe ...
-
一旦我验证了write_http与我的python插件没有合作,我发现了罪魁祸首: https : //github.com/collectd/collectd/issues/716使用元数据解决方法解决了这个问题。 Once I verified that write_http was working just not with my python plugin I found the culprit here: https://github.com/collectd/collectd/issues/71 ...
-
最终解决。 打开日志文件插件后: LoadPlugin logfile
LogLevel info File "/var/log/collectd.log" Timestamp true 我发现nginx插件没有安装: [2014-10-14 06:30:59] plugin_load: Could not find plugin "nginx" in /usr/lib64/collectd [2014-10-14 06:30 ... -
Grafana - 如何整合InfluxDB和CollectD的指标(Grafana - How to consolidate Metrics from InfluxDB and CollectD)[2023-01-26]
谢谢@AussieDan 。 这实际上让我很尴尬,甚至连他们的网站都没有看过。 我只访问了debian.org网站。 答案以最完美的方式解决了我的问题。 Thanks @AussieDan. It's actually kind a embarrassing that i haven't even take a look on their website. I only visited the debian.org website. The Answer solves my Problem on the m ...