MySQL event scheduler waiting on empty queue since server restarted 12 days ago

I noticed a process on the server which has been running for more than 12 days, which I think coincides with the last time MySQL was restarted.

mysql> SHOW FULL PROCESSLIST;  +---------+-----------------+-----------+------+---------+---------+------------------------+-----------------------+ | Id      | User            | Host      | db   | Command | Time    | State                  | Info                  | +---------+-----------------+-----------+------+---------+---------+------------------------+-----------------------+ |       5 | event_scheduler | localhost | NULL | Daemon  | 1098372 | Waiting on empty queue | NULL                  | | 1774483 | root            | localhost | NULL | Query   |       0 | starting               | SHOW FULL PROCESSLIST | +---------+-----------------+-----------+------+---------+---------+------------------------+-----------------------+ 2 rows in set (0.00 sec) 

There are no events, and I haven’t attempted to created any.

mysql> SELECT * FROM information_schema.EVENTS;  Empty set (0.00 sec) 

This is actively using up to 8% of my server’s CPU.

Is there a way of determining what this is, or why it was started? Will this try to run every time I restart MySQL? If so, what is it ‘waiting’ for and do I need to tweak my configuration at all to prevent this?

MySQL 8.0.21

how to delete specific range of data from system queue data table?

due to sudden increase of my database .mdf file we check there are 4 internal queue message table are increase unexpectedly. so we decided to delete some range of data from these table.

we try this code:

declare @c uniqueidentifier while(1=1) begin     select top 1 @c = conversation_handle from dbo.queuename     if (@@ROWCOUNT = 0)     break     end conversation @c with cleanup end   

but its try to delete all data and due to space limitation the query cannot execute. my internal message queue table :

enter image description here

enter image description here

Is there a known way to make an efficient, compact, and fully persistent stack or queue?

In the world of mutable/ephemeral data structures and imperative programming languages, one of the classic ways to implement a stack or queue is to use array doubling: use mutation to fill up or empty an array, doubling or halving to expand/contract. Such stacks/queues have several nice properties:

  1. They use at most twice as much memory as strictly necessary.
  2. They involve minimal indirection.
  3. They use cache efficiently.
  4. They have amortized $ O(1)$ insertion and deletion operations.

In a purely functional system, this approach falls down quite flat, because "mutate the array to fill/empty" becomes very expensive: the array has to be copied each time. I was wondering if there might be some reasonable compromise approach, making something more compact than classical approaches (a la Okasaki) but still with constant amortized time operations. Stacks are simpler, so I started thinking about those. My first attempt (in Haskell notation) was

data Queue a   = Shallow !(Array a)   | Deep !(Array a) (Queue a) 

with the rule that the array at depth $ n$ must have either $ 0$ or $ 2^n$ elements. Unfortunately, this doesn’t look like it’s nearly good enough. It appears that insertions impose an $ O(\log n)$ amortized cost, since flipping from a 1 digit to a 0 digit gets more expensive the deeper it happens in the tree. My next attempt was the same, but using skew binary numbers instead of binary numbers. Same deal. Is there some trick I’m missing, or am I asking to have my cake and eat it too?

Implementing Queue operations in $\Theta(1)$

We want to implement a Queue which has two special operations besides the regular Queue operations: $ getMiddle$ (returns the element from the middle of the Queue, for example, if the Queue has 7 elements, it returns the 4th element, if the Queue has 6 elements, it returns the 3rd or the 4th) and $ popMiddle$ (removes the middle element). We want both of these operations and all the other Queue operations to run in $ \theta(1)$ . Pick a suitable data structure for representing the Queue, implement the $ popMiddle$ , pop and push operations and explain in short how the other operations would be implemented.

I was thinking that the linked list would be a good pick if we keep in mind also the tail. But there is a problem when popping the middle because we have to iterate until there. An array would not be good because when erasnig we have to move all the elements to the left, if not there is no suitable formula to find the middle. Does somebody have better ideas?

Debugging Priority queue implementation supporting priority update [closed]

Please let me know if you require any additional information, but please help me out here.

For an efficient implementation of algorithms like Dijkstra’s and Prim’s, we require a priority queue that supports decrease priority operation. I’ve come up with the following code(heap based priority queue) for this which stores the index of each entry in the priority queue using a HashMap.

import java.util.HashMap; import java.util.NoSuchElementException;  public class Heap<Key extends Comparable<Key>> {     private Key[] heap;     private int maxN, n;     private HashMap<Key, Integer> map;     @SuppressWarnings("unchecked")     public Heap(int maxN) {         if(maxN < 0 ) throw new IllegalArgumentException();         this.maxN = maxN;         n = 0;         heap = (Key[]) new Comparable[maxN];         map = new HashMap<>();     }      boolean isEmpty() {         return n == 0;     }      boolean insert(Key e) {         if(n +1 > maxN) throw new IllegalArgumentException("maximum capacity reached " + maxN);         heap[n] = e;         map.put(e,n);         int i = n;         while ( (i+1)/2 - 1 >= 0){             if ( e.compareTo(heap[(i+1)/2 - 1]) < 0 ) {                 swap(i, (i+1)/2 - 1);                 i = (i+1)/2 - 1;             }             else                  break;         }         n++;         return true;     }      Key extractMin() {         if(n == 0) throw new NoSuchElementException("Priority queue underflow ");         Key min = heap[0];         swap(0, n-1);         map.remove(min);         n--;         int j = 0, s;         while(j <= n/2 - 1){             if(j == n/2 -1 && n == (j+1)*2 )                 s = (j+1)*2 - 1;             else                  s = heap[(j+1)*2 - 1].compareTo(heap[(j+1)*2]) < 0 ? (j+1)*2 - 1 : (j+1)*2;              if(heap[j].compareTo(heap[s]) > 0 ){                 swap(j, s);                 j = s;             }             else break;         }         return min;     }      Key delete(Key e){         if(!map.containsKey(e)) throw new NoSuchElementException(e+"does not exist ");         int j = map.get(e), s;         Key del = heap[j];         swap(j, n-1);         map.remove(e);         n--;         while( j <= n/2 - 1){             if(j == n/2 -1 && n == (j+1)*2)                 s = (j+1)*2 - 1;             else                 s = heap[(j+1)*2 - 1].compareTo(heap[(j+1)*2]) < 0 ? (j+1)*2 - 1 : (j+1)*2;              if(heap[j].compareTo(heap[s]) > 0 ){                 swap(j, s);                 j = s;             }             else break;         }         return del;     }      boolean decreasePriority(Key e){         if(n == 0)             return insert(e);         if(map.containsKey(e))             delete(e);         return insert(e);     }      private void swap(int i, int j) {         Key t = heap[i];         heap[i] = heap[j];         heap[j] = t;         map.replace(heap[i], i);         map.replace(heap[j], j);     }      @Override     public String toString() {         String res = "[";         int i;         for (i = 0; i < n-1; i++)             res += heap[i] + ", ";         res += heap[i]+"]";         return res;     } } 

For the problem I’m working on the program is supposed to output the total weight of the minimum spanning tree found by applying Prim’s algorithm. The input graph is a 500 node graph, and the answer obtained by this implementation is incorrect. I’m certain that the issue lies with the Heap and not with my implementation of Prim’s algorithm because using the inbuilt priority queue in java outputs the correct answer. Here is my Program running Prims’s algorithm.

import java.io.FileNotFoundException; import java.io.FileReader; import java.util.ArrayList; import java.util.List; import java.util.Scanner;  class Edge<Key>{     Key v;     int w;     public Edge(Key v, int w){         this.v = v; this.w = w;     }     @Override     public String toString(){         return "("+v+","+w+")";     } }  class vertex implements Comparable<vertex>{     int position, dis;     public vertex(int position){         this.position = position;         dis = Integer.MAX_VALUE;     }     @Override     public int compareTo(vertex v) {         if(dis > v.dis)             return 1;         if(dis < v.dis)             return -1;         return 0;     }     @Override     public String toString(){         return Integer.toString(position+1);     } } public class Prims {     public static void main(String[] args) throws FileNotFoundException {         Scanner in = new Scanner(new FileReader("prims.txt"));         int n = in.nextInt(), m = in.nextInt();         List<List<Edge<vertex>>> graph = new ArrayList<List<Edge<vertex>>>();         List<vertex> nodes = new ArrayList<vertex>();         for(int i = 0; i<n; i++){             graph.add(new ArrayList<>());             nodes.add(new vertex(i));         }         while(m-- > 0){             int u = in.nextInt()-1, v = in.nextInt()-1, w = in.nextInt();             graph.get(u).add(new Edge<vertex>(nodes.get(v), w));             graph.get(v).add(new Edge<vertex>(nodes.get(u), w));         }         in.close();         long st = System.currentTimeMillis();         System.out.println(prims(graph,nodes));         long end = System.currentTimeMillis();         System.out.println("Runtime = "+(end-st)+"ms");     }     static int prims(List<List<Edge<vertex>>> graph, List<vertex> nodes){         int n = graph.size(), weight = 0;         boolean[] inSpanTree = new boolean[n];         Heap<vertex> pq = new Heap<>(n);         inSpanTree[0] = true;         for(Edge<vertex> e : graph.get(0)){             e.v.dis = e.w;             pq.insert(e.v);         }         while(!pq.isEmpty()){             vertex u = pq.extractMin();             inSpanTree[u.position] = true;             weight += u.dis;             for(Edge<vertex> e : graph.get(u.position)){                 if(!inSpanTree[e.v.position]){                     if(e.v.dis > e.w){                         e.v.dis = e.w;                         pq.decreasePriority(nodes.get(e.v.position));                     }                 }             }         }         return weight;     } } 

If for this same implementation I use the inbuilt priority queue I get the correct output(-3612829)

static int prims(List<List<Edge<vertex>>> graph, List<vertex> nodes){         int n = graph.size(), weight = 0;         boolean[] inSpanTree = new boolean[n];         PriorityQueue<vertex> pq = new PriorityQueue<>();         inSpanTree[0] = true;         for(Edge<vertex> e : graph.get(0)){             e.v.dis = e.w;             pq.add(e.v);         }         System.out.println(pq);         while(!pq.isEmpty()){             vertex u = pq.poll();             if(u.position == 307)                 System.out.println(pq);             inSpanTree[u.position] = true;             weight += u.dis;             for(Edge<vertex> e : graph.get(u.position)){                 if(!inSpanTree[e.v.position]){                     if(e.v.dis > e.w){                         e.v.dis = e.w;                         pq.remove(nodes.get(e.v.position));                         pq.add(nodes.get(e.v.position));                     }                 }             }         }         return weight;     } 

My Heap implementation works for almost all test cases even up to 300 nodes. I don’t understand how to debug and find out where the problem lies. Here is the link to the Problem input:

https://d3c33hcgiwev3.cloudfront.net/_d4f3531eac1d289525141e95a2fea52f_edges.txt?Expires=1589673600&Signature=WSP-z481nsQgNDfN6zo0XNWy9nNTLAIty2k4HNhoQgW3pAsY0vUVaMdjg3g-UnKz9tKajuYcgGpYO3cw9H7N24tqescamo0q0n3Rykfb6BSkcI~DiKuiGpeA4gb630CU4gLAS8tDoaFRCjKNiyXAbXqHLeWhmGAmOrAnYl2rAMU_&Key-Pair-Id=APKAJLTNE6QMUY6HBC5A 

Can someone please help me debug my Heap implementation, I’ve been stuck a long time with this now. Thanks in advance.

Implementing an efficent priority queue using only stacks

Is it possible to implement an efficient priority queue (as efficient as a heap) only using the stack data structure?

The usual efficiency for a priority queue which is implemented using a heap is :

  • get min – $ O(1)$
  • extract min – $ O(\log n)$
  • add – $ O(\log n)$

Would it be possible to do something with the same complexity using only stacks?

Comparing shortest path distance and relation between two modes present in FIFO queue at the same time during breadth first traversal

I came across following problem:

Consider two vertices $ a$ and $ b$ that are simultaneously on the FIFO queue at same point during the execution of breadth first search from $ s$ in an undirected graph. Then which of the following is true:

  1. The number of edges on the shortest path between $ s$ and $ a$ is at most one more than the number of edges on the shortest path between $ s$ and $ b$ .
  2. The number of edges on the shortest path between $ s$ and $ a$ is at least one less than the number of edges on the shortest path between $ s$ and $ b$ .
  3. There is a path between $ a$ and $ b$ .
  4. $ a$ may lie on shortest path from $ s$ to $ b$ .

The solution just said first three may hold separately. But that really left me confused. Especially it did not say anything about point 4.

Here is what I guess is correct:

  1. The shortest path distance of two nodes simultaneously present in FIFO queue can differ at max by 1. That is one node may be closer to source by at max just 1 edge than the other or it may be present at the same distance from source as other node. So either point 1 is correct or point 2, but not both. Am I right with this?

  2. Also what is significance of “at most” and “at least” in point 1 and point 2? I feel the difference between shortest path distance if two nodes can be “at most” 1. I guess “at most one more” aligns with this, but “at least one less” does not. That is shortest path distance of node $ a$ cannot be lesser than that of node $ b$ by 2 or more.

  3. I feel point 3 will always be true as there will always be path from $ a$ to $ b$ going through $ s$

  4. I feel point 4 is always false, because we dequeue the node $ a$ and then enqueue all its neighbours, one of which is $ b$ . So such $ a$ and $ b$ cannot be in the queue at the same time.

Am I correct with these?

Relation Between Priority Queue, Heap, Tree

There are $ 2$ “basic”/”fundamental” data structures due to the way memory works:

  1. array
  2. linked list

Then there are ADT that we implement using those two, for example: stack, queue and more.

When we arrive to priority queue we first need to implement and ADT called heap which can be implement using:

  1. array
  2. tree (which is ADT) the can be implemented using both array and linked list

So we have

array/linked list $ \subset$ tree $ \subset$ priority queue?

enter image description here

Need help for finding a user-friendly item queue component layout and presentation

I’m looking for alternate layout/UX ideas for presenting an item queue component.

The data and behavior I’m to present is a linear queue, a stack of items — digits, letters, small images. A collection of small things.

The queue can hold typically between 3 and 6 items at a time.

If an item is added to the queue when it has already reached its maximum capacity, the item which was added first should be pushed out (deleted) and the new item added to the end of the queue.

So if I have this arrangement at first for a queue of 4:

ABCD 

…and I want to push an “E”, then this is what I should get:

BCDE 

So far this is fine and straightforward, but I wonder if there’s any other way to visually arrange the items: instead of the linear layout could I use a grid perhaps? For example if I have a queue of 6, can I show it like this?

AB CD EF 

…and if I push a “G”, then of course this is what I should see:

BC DE FG 

But I’m not sure just how user-friendly this is.

I can use visual animation to indicate where each item was relocated, and I can perhaps fade out or shrink the item that gets discarded, but I’m concerned that this might be just too busy, too many things would change at once.

Does anybody have any recommendations for me?