i have a table in my database that is described as follows: -- Table: public.devicemeasurement_mqtt  -- DROP TABLE public.devicemeasurement_mqtt;  CREATE TABLE public.devicemeasurement_mqtt (     measurement_id integer NOT NULL DEFAULT nextval('devicemeasurement_mqtt_measurement_id_seq'::regclass),     insert_time timestamp with time zone NOT NULL,     data jsonb NOT NULL,     smart_device_id integer NOT NULL,     CONSTRAINT devicemeasur_smart_device_id_ee500e1e_fk_d FOREIGN KEY (smart_device_id)         REFERENCES public.device_mqtt (device_id) MATCH SIMPLE         ON UPDATE NO ACTION         ON DELETE NO ACTION         DEFERRABLE INITIALLY DEFERRED ) WITH (     OIDS = FALSE ) TABLESPACE pg_default;  ALTER TABLE public.devicemeasurement_mqtt     OWNER to postgres;  GRANT ALL ON TABLE public.devicemeasurement_mqtt TO postgres;  -- Index: dev_insert__2df020_idx  -- DROP INDEX public.dev_insert__2df020_idx;  CREATE INDEX dev_insert__2df020_idx     ON public.devicemeasurement_mqtt USING btree     (insert_time DESC NULLS FIRST)     TABLESPACE pg_default;   -- Index: devicemeasurement_mqtt_smart_device_id_ee500e1e  -- DROP INDEX public.devicemeasurement_mqtt_smart_device_id_ee500e1e;  CREATE INDEX devicemeasurement_mqtt_smart_device_id_ee500e1e     ON public.devicemeasurement_mqtt USING btree     (smart_device_id ASC NULLS LAST)     TABLESPACE pg_default;  This table, is continuously used from a service that inserts tons of data every minute (at this time it contains around 3 milions of rows), now, in the current situation, when i have to select one device that has continuous measurements the problem does not exist, but, suppose that i have to select the measurements for a specific device that was in use three months ago and now it's disabled (so, no more new measurements), the execution of a simple and effective query like below is really slow, taking up 40 seconds to complete: This is the reference query that generates this slow select: EXPLAIN (BUFFERS,ANALYZE)  SELECT    devicemeasurement_mqtt.measurement_id,    devicemeasurement_mqtt.insert_time,   devicemeasurement_mqtt.data,   devicemeasurement_mqtt.smart_device_id FROM    devicemeasurement_mqtt  WHERE    devicemeasurement_mqtt.smart_device_id = 4  ORDER BY    devicemeasurement_mqtt.insert_time DESC LIMIT 15  and here you can find:  and the  Limit  (cost=0.43..40.04 rows=15 width=264) (actual time=39133.474..39134.059 rows=15 loops=1)   Buffers: shared hit=22093 read=112101   -&gt;  Index Scan using dev_insert__2df020_idx on devicemeasurement_mqtt  (cost=0.43..356203.28 rows=134878 width=264) (actual time=39133.471..39134.055 rows=15 loops=1)         Filter: (smart_device_id = 4)         Rows Removed by Filter: 1794148         Buffers: shared hit=22093 read=112101 Planning Time: 0.133 ms Execution Time: 39134.085 ms  I'll be glad if someone will help me to figure out!
I am running a query like   select id from students where school_id='67153fb1-8f79-441d-a747-ca3778cf6d3d';   on table that looks like                                      Table "public.students"           Column       |            Type             |             Modifiers                   -------------------+-----------------------------+------------------------------------      id                | uuid                        | not null default gen_random_uuid()      school_id        | uuid                        |  Indexes:     "students_pkey" PRIMARY KEY, btree (id)     "students_school_id_idx" btree (school_id)   The query plan for the select statement with just where looks like below-  explain select id from students where school_id='67153fb1-8f79-441d-a747-ca3778cf6d3d';                                             QUERY PLAN                                             --------------------------------------------------------------------------------------------------  Bitmap Heap Scan on students  (cost=581.83..83357.10 rows=24954 width=16)    Recheck Cond: (school_id = '67153fb1-8f79-441d-a747-ca3778cf6d3d'::uuid)    -&gt;  Bitmap Index Scan on students_school_id_idx  (cost=0.00..575.59 rows=24954 width=0)          Index Cond: (school_id = '67153fb1-8f79-441d-a747-ca3778cf6d3d'::uuid)   This is fairly fast.  Now we add order by to the query with id that degrades the query.(Such a query is generated by Rails like student.first with some condition)  explain select id from students where school_id='67153fb1-8f79-441d-a747-ca3778cf6d3d' order by id asc limit 1;                                                  QUERY PLAN                                                  ------------------------------------------------------------------------------------------------------------  Limit  (cost=0.43..488.51 rows=1 width=16)    -&gt;  Index Scan using students_pkey on students  (cost=0.43..12179370.22 rows=24954 width=16)          Filter: (school_id = '67153fb1-8f79-441d-a747-ca3778cf6d3d'::uuid)   How can I improve the speed to return the results of this query? Currently there are around 4990731 records in the table and is taking more than 2 minutes! Its running on RDS with db.t2.medium instance.  UPDATE After running Analyze students;  explain select id from students where school_id='67153fb1-8f79-441d-a747-ca3778cf6d3d' order by id asc limit 1;                                                        QUERY PLAN                                                         -----------------------------------------------------------------------------------------------------------------      Limit  (cost=8.46..8.46 rows=1 width=16)        -&gt;  Sort  (cost=8.46..8.46 rows=1 width=16)              Sort Key: id              -&gt;  Index Scan using students_school_id_idx on students  (cost=0.43..8.45 rows=1 width=16)                    Index Cond: (school_id = '67153fb1-8f79-441d-a747-ca3778cf6d3d'::uuid)      explain analyze select id from students where school_id='67153fb1-8f79-441d-a747-ca3778cf6d3d' order by id asc limit 1;                                                                           QUERY PLAN                                                                              -----------------------------------------------------------------------------------------------------------------------------------------------------------     Limit  (cost=8.46..8.46 rows=1 width=16) (actual time=1.853..1.855 rows=1 loops=1)      -&gt;  Sort  (cost=8.46..8.46 rows=1 width=16) (actual time=1.851..1.852 rows=1 loops=1)            Sort Key: id            Sort Method: quicksort  Memory: 25kB            -&gt;  Index Scan using students_school_id_idx on students  (cost=0.43..8.45 rows=1 width=16) (actual time=1.841..1.843 rows=1 loops=1)                  Index Cond: (school_id = '67153fb1-8f79-441d-a747-ca3778cf6d3d'::uuid)     Planning time: 0.145 ms     Execution time: 1.874 ms
In  (the original movie), Marty comes back from 1955 10 mins early to prevent Doc from being shot (which he fails at). He then rolls up to the Lone Pine Mall and sees himself hit 88 mph and shoot back to 1955 (again). Marty then carries on with this life as usual. What happens to the Marty that goes back to 1955 at the end of the film?  This obviously is a recursive problem where it would create another timeline and Marty would keep coming back 10 mins early to view another Marty zip back to 1955? How do I convert a video to GIF using ffmpeg, with reasonable quality? I'm converting a video to GIF file with ffmpeg:  ffmpeg -i input.flv -ss 00:00:00.000 -pix_fmt rgb24 -r 10 -s 320x240 -t 00:00:10.000 output.gif   It works great, but output gif file has a very low quality.  Any ideas how can I improve quality of converted gif? Extended Rigid Bodies in Special Relativity I was reading Landau &amp; Lifshitz's Classical Theory of Fields and I noticed that they mention that an extended rigid body isn't "relativistically correct".   For example, if you consider a rigid rod and apply a torque at one end, by definition of being rigid, the whole body must start rotating at the same instant. But the information about the force being applied cannot travel faster than the speed of light.   The book hasn't mentioned how to resolve this paradox, and after thinking about it for a while, I'm wondering if one can even define a rigid body in a relativistically correct manner.  To summarize: How does one define a rigid body in special relativity? Error: MIXED_DML_OPERATION on setup and non-setup objects When i put the code $(f_{\mathcal{X}},f_{\mathcal{X}}^{\partial})$ I get the following:  But I want the subscripts to be aligned. How can I do this? Increment Record based on field I'm setting up a Cronjob that will backup a MySQL database I have in my server, but I don't want it to keep overwriting the same file over and over again. Instead, I want to have an array of backups to choose from, done automatically. For example:  ## Cronjob, run May 21st, 2011: mysqldump -u username -ppasword database &gt; /path/to/file/21-03-2011.sql  ## SAME Conjob, run May 28th, 2011: mysqldump -u username -ppasword database &gt; /path/to/file/28-03-2011.sql   And so on.  Is there any way that I can use the system date and/or time as some kind of variable in my Cronjob? If not, what are your suggestions to accomplish the same? What is the non-parametric equivalent of a two-way ANOVA that can include interactions? How can I get the size of an array from a pointer in C? I've allocated an "array" of mystruct of size n like this:  if (NULL == (p = calloc(sizeof(struct mystruct) * n,1))) {  /* handle error */ }   Later on, I only have access to p, and no longer have n. Is there a way to determine the length of the array given just the pointer p?  I figure it must be possible, since free(p) does just that. I know malloc() keeps track of how much memory it has allocated, and that's why it knows the length; perhaps there is a way to query for this information? Something like...  int length = askMallocLibraryHowMuchMemoryWasAlloced(p) / sizeof(mystruct)   I know I should just rework the code so that I know n, but I'd rather not if possible. Any ideas? Definition of $\mathbb{R}^\infty$ Question: Why is the topological space $\mathbb{R}^\infty$ defined to be the subset of $\prod_{i=1}^\infty \mathbb{R}_i$ consisting of sequences $(a_i)_{i=1} ^{\infty}$ such at most finitely many $a_i\neq 0$? Why does one insist on the condition that $a_i\neq0$ for at most finitely many $i$? Do separate autofocus motors exist for entry level Nikon DSLRs? How can I take a photo using a slow shutter speed without it being overexposed? When I try to take a picture using a slow shutter speed in daylight it is overexposed. How can I change the settings so it isn't overexposed? How do I delete totem's history? How do I delete totem's history displayed in it's main menu in Natty? For example if I don't want anyone to know I'm watching... ehem Simpsons a lot?  I've tried  but this doesnt work for Totem. Top Down RPG Movement w/ Correction? I would hope that we have all played Zelda: A Link to the Past, please correct me if I'm wrong, but I want to emulate that kind of 2D, top-down character movement with a touch of correction. It has been done in other games, but I feel this reference would be the easiest to relate to.  More specifically the kind of movement and correction I'm talking about is:   Floating movement not restricted to tile based movement like Pokemon and other games where one tap of the movement pad moves you one square in that cardinal direction. This floating movement should be able to achieve diagonal motion. If you're walking West and you come to a wall that is diagonal in a North East/South West fashion, you are corrected into a South West movement even if you continue holding left (West) on the controller. This should work for both diagonals correcting in both directions. If you're a few pixels off from walking squarely into a door or hallway, you are corrected into walking through the hall or down the hallway, i.e. bumping into the corner causes you to be pushed into the hall/door.   I've hunted for efficient ways to achieve this and have had no luck. To be clear I'm talking about the human character's movement, not an NPC's movement. Are their resources available on this kind of movement? Equations or algorithms explained on a wiki or something?  I'm using the XNA Framework, is there anything in it to help with this? LED accent light that slowly dims when removed from power source We've all played with different transformers and power supplies that have an LED indicator that dims before going out entirely when the power supply is unplugged.  I'm working on designing an accent light which would involve a translucent crystal light source (probably made of resin or glass if I can find a cheap supplier) containing LEDs and certain electronics, and a base which would supply electrical current. For gamers, it might appear somewhat like a Welkynd Stone. My question is what is the simplest way to cause the LEDs to dim slowly (say over 2-10 seconds) when the crystal is removed from the base? Similar to the unplugged transformer, but with an intentional and controlled dimming.  I just purchased some LEDs and plan to build a test system over the next month or two. These LEDs are in a 5 meter strip divided into 3 LED series run in parallel and rated at 12v. I do not know the amp rating of the LEDs, but I'm guessing in the 20ma range (what I've read is average for bright white). I will probably use 4 series totaling 12 LEDs in the test build.   If I have the transformer from AC power built into the base, I was guessing I could use a number of capacitors in parallel with a resistor to store electricity and slowly discharge it into the LEDs. But I'm a self-taught enthusiast so I honestly don't know if this would actually work. Nor do I know the number and ratings of capacitors and resitor that I would need.  If I have the transformer built into the crystal, the transformer and rectifier would retain a small amount of electricity, but I don't think it would be nearly enough to provide the effect I'm looking for, so something else would have to be added to make it last for several seconds.  A nicad battery with control electronics is literally my last resort for achieving this effect, and I'll probably give up on the idea before I go programming my own circuit board.  That's my main question. If anyone wants to toss in some thoughts on how to connect the crystal to the base, I'm open to suggestions. My original plan was to simply have a direct copper to copper connection with the base. But I've recently been considering an EM charging system (akin to a powermat or  my dad has). The concern with the wireless is providing consistent power to the LEDs, though it is safer. I've also learned quite a bit already about constructing the power supply from perusing this SE site, but if anyone has any suggestions for that, too, I'm all ears. For the test build I'll probably hook it up to a computer power supply, or a laptop power supply if I can find a 12v one at Goodwill or the local electronics parts store.  If I get the test model to work, I plan on building possibly a dozen of these for accent lighting around my home. I'm consistently receiving significant delays on Stack Overflow when opening the flag dialog on questions. Delays do not occur on any other StackExchange site I have checked. This started a couple days ago (as far as I can tell).  Delays occur not only when loading the initial screen, but also when loading the submenus. This is slightly confusing for a couple seconds (until you're used to it) since it appears as if the flag dialog has simply vanished.   What's going on here? I demand to know, otherwise somebody will be very upset.  Not me. I'm not going to get that upset over something like this.  But someone will.    Specs (though I know of several others who have this issue):  Windows 7 64-bit Chrome Version 30.0.1599.69m     Ping: 31ms Download: 6.88mbps   Upload: 1.07mbps Help me understand the proof for Bolzano-Weierstrass Theorem! I am running SQL Server 2012.  The SQL Server Management Studio has the option to right click on a database then select Tasks and Generate Scripts.  Is there a way to automate that via command line somehow?  I want to create a script that includes the schema and data of the entire data base.  Tools like ScriptDB and sqlpubwiz.exe all seem to target SQL Server 2005. What about SQL Server 2012? How to determine which app is causing vibration? I have a Moto G6 Play that vibrates like it is getting notifications but it's not. The vibration is inconsistent and seems random so I would like to know if there is a logcat or something I can run to log which app is calling the vibration so that I can shut it off? The same thing happens on my wife's phone, same model, and it does my head in. The device is running Android 9. What is the dimension of $R[[X]]$ where $R$ is a Noetherian ring? If $R$ is a Noetherian ring then we know that the Krull dimension of the polynomial ring $R[X]$ is $\rm dim(R)+1.$ Is there any formula for the Krull dimension of the power series ring $R[[X]] $ When $R$ is a Noetherian ring ?