POSTGRE查询满

sam10000 CSDN会员 sam10000 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
各位:
我发现POSTGRE数据库查询慢,比SQLSERVER多两倍,这是怎么回事?
我用的是C#,
新建数据库:
string connectionString = "Server=localhost;Port=5432;Username=postgres;Password=12345";
NpgsqlConnection conn = new NpgsqlConnection(connectionString);
conn.Open();
string sql = "CREATE DATABASE " + Name + " WITH OWNER = postgres ENCODING='UTF8' LC_COLLATE = 'Chinese (Simplified)_China.936' LC_CTYPE = 'Chinese (Simplified)_China.936' TABLESPACE = pg_default CONNECTION LIMIT = -1;";
NpgsqlCommand objCommand = new NpgsqlCommand(sql, conn);
objCommand.ExecuteNonQuery();
conn.Close();
conn.Dispose();
新建表:
string connectionString = "Server=localhost;Port=5432;Username=postgres;Password=12345;Database=" + DataBaseName + ";";
NpgsqlConnection conn = new NpgsqlConnection(connectionString);
conn.Open();
string sql = "CREATE TABLE " + TableName +
"( 时间 timestamp without time zone, TempratureA integer, PowerA integer,ACVoltageA integer,CoilVoltageA integer,DCCurrentA integer,HzA integer,DCVoltageA integer,StoveWaterFlowA integer,MachingWaterFlowA integer,CapVoltageA integer,INVCurrentA integer,TPreheatSA integer,TColdSA integer,RESA1 integer,RESA2 integer) WITH(OIDS = FALSE);";


NpgsqlCommand objCommand = new NpgsqlCommand(sql, conn);
objCommand.ExecuteNonQuery();

sql = "CREATE INDEX x" + TableName + " ON " + TableName + " USING btree(时间 ASC NULLS LAST);";
objCommand = new NpgsqlCommand(sql, conn);
objCommand.ExecuteNonQuery();

sql = "ALTER TABLE " + TableName + " CLUSTER ON x" + TableName + ";";
objCommand = new NpgsqlCommand(sql, conn);
objCommand.ExecuteNonQuery();

conn.Close();
查询:


string connectionString = "Server=localhost;Port=5432;Username=postgres;Password=12345;Database=" + DataBaseName + ";";
NpgsqlConnection conn = new NpgsqlConnection(connectionString);
conn.Open();


DateTime StTime, EdTime;
StTime = DateTime.Parse(StartTime);
EdTime = DateTime.Parse(EndTime);


string sql = "SELECT * FROM " + TableName + " where 时间> '" + StTime + "' and 时间<'" + EdTime + "';";
NpgsqlCommand objCommand = new NpgsqlCommand(sql, conn);

da = new NpgsqlDataAdapter(objCommand);
ds = new DataSet();
da.Fill(ds, "ds");
objCommand.Parameters.Clear();

objCommand.Dispose();
ds.Dispose();

conn.Close();
conn.Dispose();
每次查询两万多条记录,为什么比较慢,是SQLSERVER的三倍。
大师们能帮忙看一下吗?
















...全文

相关推荐

node-postgre-orm:一个Node.js postgresql ORM

节点邮编 Node.js postgre sql ORM 作者 托马斯·佩雷斯(Tomas Perez) 执照 公共区域。 没有明示或暗示的担保。 使用风险自负。

giao金

postgre admin 3-1.8.1-src

postgre 的最新用户终端,编译安装使用

wwwxuebin

易语言-易语言源码 Postgre SQL 连接池

易语言源码 Postgre SQL 连接池 基于 http://www.sanye.cx/?id=12020 的源码 二次开发... 封装了一些高级方法.. 包括,连接池+查询缓存+不知道真假的储存过程+慢查询记录 使用源码使用了E2EE支持库(模块部分思路借鉴了E2EE) 最后..个人觉得..数据量不大的情况下.mysql比较快...但是.数据量大了.感觉pgsql比较快..(也可能是因为我不太会数据库的原因造成的) 引用的模块源码已经打包了...

weixin_38735899

易语言源码 Postgre SQL 连接池

易语言源码 Postgre SQL 连接池。基于 http://www.sanye.cx/?id=12020 的源码 二次开发...封装了一些高级方法..包括,连接池+查询缓存+不知道真假的储存过程+慢查询记录。使用源码使用了E2EE支持库(模块部分思路借鉴了E2EE)。最后..个人觉得..数据量不大的情况下.mysql比较快...但是.数据量大了.感觉pgsql比较快..(也可能是因为我不太会数据库的原因造成的)。引用的模块源码已经打包了...@qq1101672929。

虚坏叔叔

Postgre9.2+Postgis2.18.rar

ArcGIS10.2、ArcGIS Sever10.2配置PostgreSQL空间数据库 文件,包括=> Postgre9.2+Postgis2.18+32为dll+64位dll

GIS小猪
评论 2
收藏 已收藏
分享
返回顶部
sam10000 CSDN会员
PostgreSQL 974 成员 1,472 内容