Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql t、 在is_标记和距离上使用组合索引可以运行查询(需要52秒),但我认为我可以做得更好。对于100万个功能,这大约需要10分钟。我必须在每个项目中运行这个查询十次,所以那将是1.4小时,仍然有点太长了…也感谢您的发布。我尝试了这个查询,这就是我想要做的;_Sql_Excel_Sqlite_Odbc - Fatal编程技术网

Sql t、 在is_标记和距离上使用组合索引可以运行查询(需要52秒),但我认为我可以做得更好。对于100万个功能,这大约需要10分钟。我必须在每个项目中运行这个查询十次,所以那将是1.4小时,仍然有点太长了…也感谢您的发布。我尝试了这个查询,这就是我想要做的;

Sql t、 在is_标记和距离上使用组合索引可以运行查询(需要52秒),但我认为我可以做得更好。对于100万个功能,这大约需要10分钟。我必须在每个项目中运行这个查询十次,所以那将是1.4小时,仍然有点太长了…也感谢您的发布。我尝试了这个查询,这就是我想要做的;,sql,excel,sqlite,odbc,Sql,Excel,Sqlite,Odbc,t、 在is_标记和距离上使用组合索引可以运行查询(需要52秒),但我认为我可以做得更好。对于100万个功能,这大约需要10分钟。我必须在每个项目中运行这个查询十次,所以那将是1.4小时,仍然有点太长了…也感谢您的发布。我尝试了这个查询,这就是我想要做的;但是,此查询的执行情况与我最初发布的查询大致相同。问题是查询执行时间是非线性的。如果我以限制100、1000和10000运行此查询,则查询时间分别为15ms、188ms和32838ms。如果是线性时间增长,我预计10000ms查询需要1.5秒。


t、 在is_标记和距离上使用组合索引可以运行查询(需要52秒),但我认为我可以做得更好。对于100万个功能,这大约需要10分钟。我必须在每个项目中运行这个查询十次,所以那将是1.4小时,仍然有点太长了…也感谢您的发布。我尝试了这个查询,这就是我想要做的;但是,此查询的执行情况与我最初发布的查询大致相同。问题是查询执行时间是非线性的。如果我以限制100、1000和10000运行此查询,则查询时间分别为15ms、188ms和32838ms。如果是线性时间增长,我预计10000ms查询需要1.5秒。33秒并不可怕,但我需要对100000个特性执行此查询。10万个功能的增长率为113倍(188/15=~1232838/15=~12)=188*12*10*32838/1000/3600=206小时。我不确定是否有可能更快地完成此查询。在代码中这样做需要100万个特性,在代码中只需要1.5分钟,但是使用这个查询我会在它完成之前就死了:)也谢谢你的发布。我尝试了这个查询,这就是我想要做的;但是,此查询的执行情况与我最初发布的查询大致相同。问题是查询执行时间是非线性的。如果我以限制100、1000和10000运行此查询,则查询时间分别为15ms、188ms和32838ms。如果是线性时间增长,我预计10000ms查询需要1.5秒。33秒并不可怕,但我需要对100000个特性执行此查询。10万个功能的增长率为113倍(188/15=~1232838/15=~12)=188*12*10*32838/1000/3600=206小时。我不确定是否有可能更快地完成此查询。在代码中执行此操作需要100万个功能,在代码中只需1.5分钟,但使用此查询在完成之前我就已经死了:)
Feature { int id, int distance, bool is_marker }
select 
*          /* I want all the data from this feature */
(select MAX(f2.distance) - f1.distance 
    from feature as f2
    where f2.is_marker && f2.distance < f1.distance) /* and the distance to the previous marker */
from feature as f2
select
*,          /* I want all the data from this feature */
(select f1.distance - MAX(f2.distance)
    from feature as f2
    where f2.distance AND f2.distance< f1.distance) /* and the distance to the previous marker */
from feature as f1
var features = featureRepository.GetAll();
var featuresWithMarkerDistance = new List<FeatureWithMarkerDistance>();
var previousMarker = null;
for(var index = 0; index < features.Length; index++) {
    var currentFeature = features[index];
    featuresWithMarkerDistance.Add(
        new FeaturesWithMarkerDistance(currentFeature, 
            feature.distance - previousMarker.distance));
    if(feature.is_marker) {
        previousMarker = feature;
    }
}

// FeatureWithMarkerDistance { int id, int distance, bool is_marker, int marker_distance }
(The underlying table)
feature_id is_marker distance
1          false     100
2          false     90
3          false     101
4          true      50
5          false     5
6          true      85
7          false     150
8          false     75
feature_id is_marker distance distance_to_closest_previous_marker
1          false     100      15
2          false     90       5
3          false     101      16
4          true      50       null
5          false     5        null
6          true      85       35
7          false     150      65
8          false     75       25
   select *          
    /* I want all the data from this feature */ 
    /* previous  = */ (select MAX(f2.distance) - f1.distance 
        from feature as f2
        where f2.is_marker && f2.distance >= previous && f2.distance < f1.distance) 
    /* and the distance to the previous marker */
    from feature as f2
select f2.*, f2.distance - f1.distance
from feature f2
left join feature f1 on f1.is_marker
                    and f2.distance > f1.distance
                    and not exists(select 1 from feature f1b
                                   where f1b.is_marker
                                     and f2.distance > f1b.distance
                                     and f1.distance < f1b.distance)
where f2.is_marker
SELECT F2.feature_id, F2.is_marker, F2.distance, 
       F2.distance - (SELECT F1.distance FROM features F1
                      WHERE F1.is_marker<>0 
                        AND F1.distance<F2.distance
                      ORDER BY F1.distance DESC
                      LIMIT 1) AS "distance_to_closest_previous_marker"
FROM features F2
SELECT *, 
       (SELECT MIN(feature.distance-distance) FROM feature AS f
               WHERE is_marker AND distance<feature.distance) 
       FROM feature;
CREATE TEMP TABLE markers_distance (distance);
CREATE UNIQUE INDEX markers_idx ON markers_distance (distance);
INSERT OR IGNORE INTO markers_distance 
       SELECT distance FROM feature WHERE is_marker;
SELECT *, 
       (SELECT MIN(feature.distance-distance) FROM markers_distance
               WHERE distance<feature.distance) 
       FROM feature;