Posts

Showing posts with the label indexing

Is there a way to use pg_trgm like operator with btree indexes on PostgreSQL?

Is there a way to use pg_trgm like operator with btree indexes on PostgreSQL? I have two tables: ref_id_t1 is filled with id_t1 values , however they are not linked by a foreign key as table_2 doesn't know about table_1. I need to do a request on both table like the following: SELECT * FROM table_1 t1 WHERE t1.c1_t1= 'A' AND t1.id_t1 IN (SELECT t2.ref_id_t1 FROM table_2 t2 WHERE t2.c1_t2 LIKE '%abc%'); Without any change or with basic indexes the request takes about a minute to complete as a sequencial scan is peformed on table_2. To prevent this I created a GIN idex with gin_trgm_ops option: CREATE EXTENSION pg_trgm; CREATE INDEX c1_t2_gin_index ON table_2 USING gin (c1_t2, gin_trgm_ops); However this does not solve the problem as the inner request still takes a very long time. EXPLAIN ANALYSE SELECT t2.ref_id_t1 FROM table_2 t2 WHERE t2.c1_t2 LIKE '%abc%' Gives the following Bitmap Heap Scan on table_2 t2 (cost=664.20..189671.00 rows=65058 width=4) (actual...

How to impliment logical indexing faster in matlab? [closed]

How to impliment logical indexing faster in matlab? [closed] I have several matrices that I need to add to one large matrix. The large matrix (300002x50) is split up by .001 seconds and the timing for the other 49 matricies (14250x2) are roughly .02 apart, but not uniformly distributed. I have tried find to index the entries from the smaller matrices into the larger matrix, but it was too slow. I have since tried: find for a = 1:length(test) aaa = abs(AF1(:,1)-test(a,1))<10^-6; AF1(aaa,index)=test(a,2); end Where test is a 14250x2 double (time,data) , AF1 is a 300002x50 double matrix and index is which column in AF1 the data will be added to. It was a bit faster, but it still takes up 99.3% (29 minutes) of the time. It works how I want it, but is there any way to implement this in a faster manner? test (time,data) AF1 index AF1 Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. A...

Why is my logical mask not working on a 2D matrix in matlab properly?

Why is my logical mask not working on a 2D matrix in matlab properly? X(100,371) %% contains 100 datapoints for 371 variables I want to keep only the data which are within mean+standard deviation:mean-standard deviation. This is how I am proceeding: mx=mean(X);sx=std(X); %%generate mean, std %%this generates mx(1,371) and sx(1,371) mx=double(repmat(mx,100,1)); %%this fills a matrix with the same datapoints, %%100 times sx=double(repmat(sx,100,1)); %% this gives mx(100,371) and sx(100,371) g=X>mx-sx & X<mx+sx; %%this creates a logical mask g(100,371) %%filled with 1s and 0s test(g)=X(g); %%this should give me test(100,371), but I get %%test(37100), which is wrong as it doesnt maintain %%the shape of X test=reshape(test,100,371) %% but when I compare this to the my original matrix %% X(100,371) I hardly see a difference (datapoints %% in test are still outside the range I want. What am I doing wrong? 1 Answer ...