为什么PostgreSQL查询在第一次新连接后的第一次请求中比在后续请求中慢?
使用几种不同的技术连接到postgresql数据库.第一次请求可能需要1.5秒.完全相同的查询将第二次花费.03秒.打开我的应用程序的第二个实例(连接到同一个数据库),第一个请求需要1.5秒,第二个请求需要.03秒.
由于我们使用的技术不同,它们在不同的点连接并使用不同的连接方法,所以我真的不认为它与我编写的任何代码有任何关系.
我认为在第一个请求之前打开连接不会执行"所有操作",因此请求会产生一些开销.
因为我已经使用了数据库,并且保留了服务器所有内容都在内存中所以索引等应该不是问题.
编辑说明 - 告诉我有关查询的信息,老实说查询看起来很不错(索引等).我真的认为postgresql在新连接的第一个查询上有某种开销.
我不知道如何证明/反驳这一点.如果我使用PG Admin III(pgAdmin版本1.12.3),所有查询看起来都很快.我第一次查询的任何其他工具都很慢.大部分时间它的速度并没有明显变慢,如果是这样的话,我总是将其用指数更新ram.但这显然不是那样的.如果我打开我的工具并执行任何其他返回结果的查询,则无论如何第二个查询都很快.如果第一个查询没有返回结果,那么第二个查询仍然很慢,那么第三个查询很快.
编辑2 即使我不认为查询与延迟有任何关系(每个第一个查询都很慢),这里有两个运行Explain(EXPLAIN ANALYZE)的结果
EXPLAIN ANALYZE
select * from company
where company_id = 39
Run Code Online (Sandbox Code Playgroud)
输出:
"Seq Scan on company (cost=0.00..1.26 rows=1 width=54) (actual time=0.037..0.039 rows=1 loops=1)"
" Filter: (company_id = 39)"
"Total runtime: 0.085 ms"
Run Code Online (Sandbox Code Playgroud)
和:
EXPLAIN ANALYZE
select * from group_devices
where device_name ilike 'html5_demo'
and group_id in ( select group_id from manager_groups
where company_id in (select company_id from company where company_name ='TRUTHPT'))
Run Code Online (Sandbox Code Playgroud)
输出:
"Nested Loop Semi Join …Run Code Online (Sandbox Code Playgroud) 一个问题,但可能没有结束,我如何从URL获取变量.在我的所有搜索中,我发现了几种非常好的方法可以A=aValue从网址中获取.
但我的问题是我需要的
?Company=FLHS&Device=Crosstown_PCC_01&A=aValue&A=secondAValue
Run Code Online (Sandbox Code Playgroud)
我需要一个网址中的两个A的数组,我需要知道这aValue是第一个,secondAValue是第二个
我有jquery Mobile.
更新
所以这就是我现在拥有的
var urlParamDevice = getURLParameter('DeviceID');
function getURLParameter(name) {
return decodeURI(
(RegExp(name + '=' + '(.+?)(&|$)').exec(location.search) || [, null])[1]
);
Run Code Online (Sandbox Code Playgroud)
getURLParameter(name)需要更强大一些.
更新2,2014/03/07 这是我从建议的答案中得出的结论
function getQueryParams(name) {
qs = location.search;
var params = [];
var tokens;
var re = /[?&]?([^=]+)=([^&]*)/g;
while (tokens = re.exec(qs))
{
if (decodeURIComponent(tokens[1]) == name)
params.push(decodeURIComponent(tokens[2]));
}
return params;
}
Run Code Online (Sandbox Code Playgroud) 我一直在搞乱一些应该简单的事情.
我已经移动了工作并试图获得我之前使用的一些基本工具,但当然我没有旧的资源来看待.
我们扩展了面板以具有一些标准属性和功能(保存,关闭,保存和关闭).
但我不能让按钮在调整大小时正确定位.我把这个ExtPanel放在一个表单上,但是当我调整大小时按钮不断消失,或者没有按预期移动(在右下角冻结).
班级
public partial class ExtPanel: UserControl
{
private System.Windows.Forms.Button btnSaveandClose;
private System.Windows.Forms.Button btnCancel;
private System.Windows.Forms.Button btnSave;
public ExtPanel ()
{
InitializeComponent ();
}
// misc things this class does...
}
public partial class ExtPanel
{
private void InitializeComponent ()
{
this.btnSaveandClose = new System.Windows.Forms.Button();
this.btnCancel = new System.Windows.Forms.Button();
this.btnSave = new System.Windows.Forms.Button();
this.panel1 = new System.Windows.Forms.Panel();
this.panel1.SuspendLayout();
this.SuspendLayout();
//
// btnSaveandClose
//
this.btnSaveandClose.Location = new System.Drawing.Point(899, 689);
this.btnSaveandClose.Name = "btnSaveandClose";
this.btnSaveandClose.Size = new System.Drawing.Size(100, 30);
this.btnSaveandClose.TabIndex …Run Code Online (Sandbox Code Playgroud) 尝试通过更改Browsable属性来删除或放置属性网格上的项目.
但除非在对象创建时设置了可浏览,否则我更改Browsable的代码不起作用.现在我可以手动添加可浏览,但是当我对我的实体进行更改(仍在开发项目以便对实体进行大量更改)时,我添加的任何其他属性都会消失.
我试图通过两种方式设置[Browsable(true)]:http://ardalis.com/adding-attributes-to-generated-classes和http://social.msdn.microsoft.com/Forums/en-US/adodotnetentityframework /线程/ 617ebfca-0f68-4b90-83fd-0da758fadbd0 /
两者似乎都实际上正确地设置了Browsable,但是当我通过属性描述符中的属性循环时,它不存在(我改变).
String fieldname = "browsable"; // I also edit "description"
PropertyDescriptor pd = TypeDescriptor.GetProperties(o.GetType())[propertyName];
object attrib = null;
AttributeCollection attribs = pd.Attributes;
foreach (Attribute a in attribs)
{
if (a.GetType() == attributeType)
{
attrib = a;
break;
}
}
// The microsoft documentation leads one to believe the following line of code would find the desired attribute,
// negating the need for the more complete foreach statement above.
// …Run Code Online (Sandbox Code Playgroud) 如果更新正在分配用户,则需要创建一个触发器。而且我们之前没有设置值。
我有这个,但是服务器不喜欢它。...我收到一个错误
'。'附近的语法不正确
在“设置”行上。
CREATE TRIGGER dbo.trgIssueAcknowledged
ON dbo.hdIssues
AFTER UPDATE
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
If (select inserted.AssignedToUserID from inserted) IS NULL
begin
return
end
If (select inserted.AssignedToUserID from inserted) = 0
begin
return
end
If (select inserted.AcknowledgeDate from inserted) IS NULL
begin
set inserted.AcknowledgeDate = GETDATE ( );
end
END
GO
Run Code Online (Sandbox Code Playgroud) .net ×1
c# ×1
javascript ×1
jquery ×1
panel ×1
postgresql ×1
properties ×1
propertygrid ×1
sql ×1
sql-server ×1
triggers ×1
winforms ×1