首先,如果这不是这类问题的地方,请告诉我,我会将其删除。
好的,所以我有一个MySQL PHP查询翻译类,可以转换为其他数据库中的MSSQL。以下测试文件生成以下结果(启用调试)
Test_File.php
include 'session_handler.php';
include 'database_connection.php';
$result = $db->query("SELECT * FROM industries LIMIT 5");
MySQL结果:
Query time was 0.00622892379761 seconds for:
SELECT * FROM industries LIMIT 5
Query time was 0.000350952148438 seconds for:
SELECT "session_id" FROM "sessions" WHERE "session_id" = '58'
Query time was 0.000293016433716 seconds for:
UPDATE "sessions" SET "value" = 'x', "expiration" = '0' WHERE "session_id" = '58'
Total query time: 0.00848698616028 seconds
MSSQL结果
Query time was 0.21740579605103 seconds for:
SELECT
c.table_schema AS "schema",
c.table_name AS "table",
c.column_name AS "column",
c.data_type AS "type"
FROM
INFORMATION_SCHEMA.COLUMNS AS c
WHERE
(c.data_type = 'nvarchar' OR
c.data_type = 'ntext' OR
c.data_type = 'nchar') AND
c.table_catalog = DB_NAME()
ORDER BY
lower(c.table_name) ASC,
lower(c.column_name) ASC
Query time was 0.21066212654114 seconds for:
SELECT TOP 5 *, CAST("industries"."industry" AS VARBINARY(MAX)) AS fmssqln__industry FROM industries
Query time was 0.21116590499878 seconds for:
SELECT "session_id" FROM "sessions" WHERE "session_id" = '58'
Query time was 0.21582698822021 seconds for:
UPDATE "sessions" SET "value" = x, "expiration" = '0' WHERE "session_id" = '58'
Total query time: 1.7053256034851 seconds
正如您所看到的,MySQL查询非常快,而转换后的查询(由类转换)需要将近2秒。
我对MSSQL的语法一无所知,所以我不确定转换的查询是否尽可能优化?
所以我的问题是 - 转换后的MSSQL查询是否是MySQL查询的正确翻译,我应该从哪里开始解决速度问题?
其他信息: MSSQL和MySQL数据库和表是完全相同的,内容和模式。
由于
答案 0 :(得分:0)
可能是PHP正在使用的驱动程序?也许SQL Server只是速度慢。你在用Express吗?它对可以使用的资源有限制。尝试SSMS中的查询并将其粘贴在顶部以获取查询时间:
SET STATISTICS TIME ON
Express的限制是listed here。因此,CPU是1个插槽,或4个内核(可能更少),RAM限制为1GB。