我试图强制MySQL使用两个索引.我正在加入一个表,我想利用两个索引之间的交叉.具体术语是使用交叉,这里是MySQL文档的链接:
http://dev.mysql.com/doc/refman/5.0/en/index-merge-optimization.html
有没有办法强制执行此功能?我的查询是使用它(它加速了),但现在无论出于什么原因它已停止.
这是我想要做的JOIN.我希望查询使用的两个索引是scs.CONSUMER_ID_1和scs_CONSUMER_ID_2
JOIN survey_customer_similarity AS scs
ON cr.CONSUMER_ID=scs.CONSUMER_ID_2
AND cal.SENDER_CONSUMER_ID=scs.CONSUMER_ID_1
OR cr.CONSUMER_ID=scs.CONSUMER_ID_1
AND cal.SENDER_CONSUMER_ID=scs.CONSUMER_ID_2
Run Code Online (Sandbox Code Playgroud) 我在R中使用shapefile ,一个是point.shp,另一个是polygon.shp.现在,我想将点与多边形相交,这意味着多边形中的所有值都应该附加到point.shp的表中.
我在包sp中尝试了overlay()和spRbind,但没有做我期望他们做的事情.
谁能给我一个提示?
我有一个向量列表:
> l <- list(A=c("one", "two", "three", "four"), B=c("one", "two"), C=c("two", "four", "five", "six"), D=c("six", "seven"))
> l
$A
[1] "one" "two" "three" "four"
$B
[1] "one" "two"
$C
[1] "two" "four" "five" "six"
$D
[1] "six" "seven"
Run Code Online (Sandbox Code Playgroud)
我想计算列表元素的所有可能的成对组合之间的重叠长度,即(结果的格式无关紧要):
AintB 2
AintC 2
AintD 0
BintC 1
BintD 0
CintD 1
Run Code Online (Sandbox Code Playgroud)
我知道combn(x, 2)可以用来得到一个矢量中所有可能的成对组合的矩阵,length(intersect(a, b))这会给我两个向量重叠的长度,但我想不出把这两个东西放在一起的方法.
任何帮助深表感谢!谢谢.
这是我的查询:
-- Sids of suppliers who supply a green part AND a red part
(SELECT Suppliers.sid
FROM Suppliers
JOIN Catalog ON Catalog.sid = Suppliers.sid
JOIN Parts ON Parts.pid = Catalog.pid
WHERE Parts.color = "red")
INTERSECT
(SELECT Suppliers.sid
FROM Suppliers
JOIN Catalog ON Catalog.sid = Suppliers.sid
JOIN Parts ON Parts.pid = Catalog.pid
WHERE Parts.color = "green");
Run Code Online (Sandbox Code Playgroud)
这是错误:
错误1064(42000):您的SQL语法有错误; 检查与MySQL服务器版本对应的手册,以便在第6行的"INTERSECT(SELECT Suppliers.sid FROM Suppliers JOIN Catalog ON Catalog.sid = Sup")附近使用正确的语法.
我究竟做错了什么?
这是架构:
供应商(sid:整数,sname:字符串,地址字符串)
零件(pid:整数,pname:字符串,颜色:字符串)
目录(sid:整数,pid:整数,成本:实际)
bold =主键
为什么在Groovy中,当我创建2个列表时,如果我执行a.intersect(b)和b.intersect(a)会有区别:
def list1 = ["hello", "world", "world"];
def list2 = ["world", "world", "world"];
println( "Intersect list1 with list2: " + list1.intersect( list2 ) );
println( "Intersect list2 with list1: " + list2.intersect( list1) );
Run Code Online (Sandbox Code Playgroud)
痕迹:
Intersect list1 with list2: [world, world, world]
Intersect list2 with list1: [world, world]
Run Code Online (Sandbox Code Playgroud)
(你可以在这里复制:http://groovyconsole.appspot.com/如果你想测试它)
如果数组都包含唯一元素,那么它可以正常工作.一旦你开始添加重复项,它就会变得奇怪:
def list1 = ["hello", "world", "test", "test"];
def list2 = ["world", "world", "world", "test"];
println( "Intersect list1 with list2: " + list1.intersect( list2 ) );
println( …Run Code Online (Sandbox Code Playgroud) 我一直在寻找一个小时的答案,但很难找到关于这个主题的任何内容.
我有一个与Objective-c相关的问题.我正在制作一个应用程序,其中UIView检查来自用户的触摸,如果用户触摸并移动他/她的手指,则绘制使用UIBezierPath的路径.如果用户绘制以使路径自身相交,则它应从屏幕上消失.当用户完成绘制图案时,路径中最后一个点的一条线应自动连接到路径中的第一个点(我正在使用方法"closePath"),如果此线与另一个"线"相交"在路径中,路径也应该从屏幕上消失.
我将每个触摸点存储在CGPoint中,我将其存储在另一个名为Line的类中作为A点和B点.然后我将"line"保存到名为"lines"的NSMutableArray中.每次将一个点添加到路径时,我都会检查该点与它之前绘制的点之间的线是否与行中的任何"行"相交( - (BOOL)checkLineIntersection:(CGPoint)p1 :(CGPoint)p2:(CGPoint)p3:(CGPoint)p4)我从本教程中获得"http://www.iossourcecode.com/2012/08/02/how-to-make-a-game-like-切的绳部分-2 /".
问题
问题是,当我运行应用程序时,它有时会起作用,但有时当我绘制时,线条与路径相交并不会消失.我无法弄清楚为什么......当我慢慢画画时,似乎更常见.
代码:
MyView.h:
#import <UIKit/UIKit.h>
#import "Line.h"
@interface MyView : UIView {
NSMutableArray *pathArray;
UIBezierPath *myPath;
NSMutableArray *lines;
Line *line;
}
@end
Run Code Online (Sandbox Code Playgroud)
MyView.m:
#import "MyView.h"
@implementation MyView
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
pathArray=[[NSMutableArray alloc]init];
}
return self;
}
- (void)drawRect:(CGRect)rect
{
[[UIColor redColor] setStroke];
[[UIColor blueColor] setFill];
for (UIBezierPath *_path in pathArray) {
//[_path fill];
[_path strokeWithBlendMode:kCGBlendModeNormal alpha:1.0];
}
}
#pragma mark - Touch …Run Code Online (Sandbox Code Playgroud) 我想从两个哈希数组中得到union/intersect/difference,例如:
array1 = [{:name =>'Guy1', :age => 45},{:name =>'Guy2', :age => 45}]
array2 = [{:name =>'Guy1', :age => 45},{:name =>'Guy3', :age => 45}]
Run Code Online (Sandbox Code Playgroud)
...
p array1 - array2
=> [{:name=>"Guy2", :age=>45}]
p array2 - array1
=> [{:name=>"Guy3", :age=>45}]
p array1 | array2
=> [{:name=>"Guy1", :age=>45}, {:name=>"Guy2", :age=>45}, {:name=>"Guy3", :age=>45}]
Run Code Online (Sandbox Code Playgroud)
但是,当我只想根据名称进行比较并忽略年龄而不需要从哈希中删除它们时,例如:
array1 = [{:name =>'Guy1', :age => 45},{:name =>'Guy2', :age => 45}]
array2 = [{:name =>'Guy1', :age => 46},{:name =>'Guy3', :age => 45}]
Run Code Online (Sandbox Code Playgroud)
在这种情况下,我没有得到我想要的结果b/c年龄不同.
array1 - array2
=> [{:name=>"Guy1", :age=>45}, {:name=>"Guy2", …Run Code Online (Sandbox Code Playgroud) 我遇到了这个例子,我不明白这意味着什么.
(SELECT drinker FROM Frequents)
EXCEPT ALL
(SELECT drinker FROM Likes);
Run Code Online (Sandbox Code Playgroud)
关系:频繁(饮酒者,酒吧),喜欢(饮酒者,啤酒)
在这种情况下,ALL会做什么?结果与下面的查询有何不同?
(SELECT drinker FROM Frequents)
EXCEPT
(SELECT drinker FROM Likes);
Run Code Online (Sandbox Code Playgroud) sql set-difference set-operations intersect set-intersection
我正在使用MS SQL.
我有一个巨大的表与索引来快速查询:
select userid from IncrementalStatistics where
IncrementalStatisticsTypeID = 5 and
IncrementalStatistics.AssociatedPlaceID = 47828 and
IncrementalStatistics.Created > '12/2/2010
Run Code Online (Sandbox Code Playgroud)
它在不到1秒的时间内返回.该表有数十亿行.只有大约10000个结果.
我希望这个查询也能在大约一秒钟内完成:
select userid from IncrementalStatistics where
IncrementalStatisticsTypeID = 5 and
IncrementalStatistics.AssociatedPlaceID = 47828 and
IncrementalStatistics.Created > '12/2/2010'
intersect
select userid from IncrementalStatistics where
IncrementalStatisticsTypeID = 5 and
IncrementalStatistics.AssociatedPlaceID = 40652 and
IncrementalStatistics.Created > '12/2/2010'
intersect
select userid from IncrementalStatistics where
IncrementalStatisticsTypeID = 5 and
IncrementalStatistics.AssociatedPlaceID = 14403 and
IncrementalStatistics.Created > '12/2/2010'
Run Code Online (Sandbox Code Playgroud)
但它需要20秒.所有单个查询都需要<1秒,并返回大约10k的结果.
我希望SQL内部将每个子查询的结果抛出到哈希表中并进行哈希交集 - 应该是O(n).结果集足够大以适应内存,因此我怀疑这是一个IO问题.
我编写了一个备用查询,它只是一系列嵌套的JOIN,这也需要大约20秒,这是有道理的.
为什么INTERSECT这么慢?它是否在查询处理的早期阶段缩减为JOIN?
我有两个表,列数相同,没有主键(我知道,这不是我的错).现在我需要删除表B中存在的表A中的所有行(它们相等,每个行有30列).
我认为最直接的方法是做一个INNER JOIN并解决我的问题.但是,为所有列编写条件(担心NULL)并不优雅(可能因为我的表也不优雅).
我想用INTERSECT.我不知道该怎么办?这是我的第一个问题:
我试过(SQL Fiddle):
declare @A table (value int, username varchar(20))
declare @B table (value int, username varchar(20))
insert into @A values (1, 'User 1'), (2, 'User 2'), (3, 'User 3'), (4, 'User 4')
insert into @B values (2, 'User 2'), (4, 'User 4'), (5, 'User 5')
DELETE @A
FROM (SELECT * FROM @A INTERSECT SELECT * from @B) A
Run Code Online (Sandbox Code Playgroud)
但是所有行都从表中删除了@A.
这让我想到了第二个问题:为什么命令DELETE @A FROM @B会从表中删除所有行@A …
intersect ×10
sql ×5
algorithm ×2
arrays ×2
mysql ×2
r ×2
combinations ×1
combn ×1
drawing ×1
groovy ×1
hash ×1
join ×1
list ×1
objective-c ×1
ruby ×1
shapefile ×1
spatial ×1
sql-delete ×1
sql-server ×1
uibezierpath ×1
union ×1