Skip to main content
Share Your Experience: Take the 2024 Developer Survey

Questions tagged [limits]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
0 votes
1 answer
108 views

Why doesn't Postgres apply limit on groups when retrieving N results per group?

I've come across many questions/answers for Greatest/Top N per group type problems that explain how to solve the problem - generally some variation of row_number() or CROSS JOIN LATERAL, but I'm ...
Seanvm's user avatar
  • 101
0 votes
1 answer
35 views

Force MySQL to use specific index on ORDER BY clause with LIMIT to satisfy join

MySQL 8.0.30 I have three tables defined: C CT T CT is a linking table (many-to-many between C & T) The query I'm trying to optimize is of the following kind: SELECT C.*, T.* FROM C JOIN CT ON C....
ktn's user avatar
  • 1
0 votes
1 answer
446 views

Can I set a row-limit for query results that throws an ERROR if the result set exceeds that limit?

I'm looking for a way to protect my database against runaway queries issued by an application. I have control over both the application and the database. It occurs to me that I can protect against two ...
Christopher Schultz's user avatar
0 votes
1 answer
159 views

'Limit INT OFFSET @variable' throw runtime error in mysql server

I'm trying to solve this problem in Hackerrand The problem asks for the median in a specific column my code: SET @VAE = (SELECT COUNT(*) FROM STATION); SET @VAE1 = ROUND(@VAE/2)-1; SELECT LAT_N FROM ...
ahmad alghadban's user avatar
0 votes
1 answer
538 views

Why does my LIMITed SELECT fetch the last record of the table, not the first?

I read that to fetch the first table record, you may use LIMIT 1. I tried to apply that knowledge to my JOIN statement and got a diametrically opposite result. It joined the last record of the joined ...
Sergey Zolotarev's user avatar
2 votes
1 answer
38 views

How to get the most recent result sets when grouping key and date are in separate tables

Good evening! I'm having some difficulty. I'm trying to obtain the most recent row from a few tables using SQL. I can do this using a loop in code, but it requires a lot of round trips to the database ...
jeremysawesome's user avatar
3 votes
1 answer
414 views

How to limit the amount of values within a postgres table which are updated

using the following sample: CREATE TABLE tbl( x integer, y integer ) INSERT INTO tbl SELECT g AS x FROM generate_series(1, 10) AS g; Which gives: x | y ----+--- 1 | 2 | 3 | ...
baxx's user avatar
  • 296
0 votes
1 answer
231 views

MariaDB: Limit changes query plan and makes query very slow

It's counter-intuitive and weird to see how adding "LIMIT 2" changes whole plan for MariaDB (version 10.6.7) from using one index and having total time of 2 seconds into another index with ...
Dmitriy Gorbenko's user avatar
0 votes
1 answer
699 views

How to limit CPU by Db2 instance?

On Linux/x86_64 I have several Db2 database instances and most of them have one database per instance. Today I have had one "run away instance" that consumed most of the CPU resources of ...
folow's user avatar
  • 339
0 votes
0 answers
341 views

MySQL query: multiple select with different conditions and LIMIT for each, but also LIMIT whole query + paginator friendly

I would like to write SQL query (for MySQL) that is able to SELECT x rows by condition1 from table1 y rows by condition2 from table1+join1 z rows by condition3 from table1+join2 But on every page (...
Nick's user avatar
  • 1
2 votes
3 answers
69 views

How do I block all IP addresses from connecting remotely to Cassandra?

I want access to remote cassandra with one ip address. how can I change cassandra.yaml to block all ip address except ip that I want to connect? Can I do by cassandra.yaml ?
RezaRastgoo's user avatar
0 votes
2 answers
3k views

How to limit the number of rows in a mysql table

How can I set a limit of rows to a mysql table? (I am using php) POSSIBLE METHOD-1: When the user tries to SIGN-UP I can select everything from the TABLE and get the number of ROWS in the TABLE and ...
user avatar
1 vote
0 answers
672 views

Very slow MariaDB query when adding ORDER BY/LIMIT but there are no rows

I am facing an issue with MariaDB 10.1 on a log table with the following (simplified) structure: CREATE TABLE logs ( log_id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY, log_date TIMESTAMP DEFAULT ...
Matteo Tassinari's user avatar
0 votes
1 answer
1k views

Best practice for SQL table names when using sub namespaces that exceed maximum table name length

I have a MySQL database that includes many tables named according to a namespace that uses sub names and underscores (_ as in a_b_c), such as the following: life_domain_kingdom_phylum ...
Arya's user avatar
  • 134
2 votes
1 answer
3k views

Limiting the number of records from nested INNER JOIN table

The context is as follows: We have 3 tables: We'll call them A,B and C. A has a foreign key referencing table B, we'll call it "bId". The relationship is a ManyToOne. (One record in B can ...
Robert Tabacaru's user avatar
0 votes
1 answer
193 views

mySQL Query with a LIMIT on a row value

I am trying to replace a lot of queries like this with a single query. SELECT * FROM y WHERE x = a ORDER BY timestamp LIMIT 50 SELECT * FROM y WHERE x = b ORDER by timestamp LIMIT 50 SELECT * FROM y ...
Christopher Padfield's user avatar
0 votes
1 answer
452 views

data model limit rows per user

This is regarding to postgres that I was asked to create data model which has a relationship with user. For example a new data model called Comment M:1 User, but while creating the data model is it ...
Dora's user avatar
  • 125
0 votes
1 answer
175 views

Determine Available Blocks of Contiguous Ids

We have a SQL Server table that has an int autoincrement primary key column on it. The table's primary key space is fragmented. For example, ids 1 through 10 are in use but then ids 11 through 100,000 ...
Manny Siddiqui's user avatar
0 votes
1 answer
52 views

Fill remaining LIMIT rows selection if conditions met are less than LIMIT number

I have a MySQL database with data in it. They all have locations (London, Liverpool, etc), I want a query to select 10 random rows with a location (for example London), and if there aren't enough to ...
D M's user avatar
  • 21
3 votes
1 answer
10k views

How to use ORDER BY and LIMIT inside JSON_AGG

I have a query which returns a desired output. SELECT shop, JSON_AGG(item_history.* ORDER BY created_date DESC) as data FROM item_history GROUP BY shop; Results: [ { "shop&...
lrai's user avatar
  • 33
0 votes
1 answer
49 views

MySQL replication username

What is the difference in using these two approaches when setting master-slave replication: Setting the binlog-do-db option on the master to choose which DBs are going to be replicated; Creating a ...
Mark's user avatar
  • 111
0 votes
2 answers
536 views

How to limit tree traversal in case of loops?

So I want to limit tree depth traversal (as the simplest recursion killer tool). Example code that turns normalized records into tree: CREATE TABLE items ( item_id serial PRIMARY KEY, title ...
Blender's user avatar
  • 75
0 votes
0 answers
427 views

postgresql, connection limit for different roles

Is possible setup in postgresql.conf connection limit for specified role globally (in some .conf file) or individually? For example, I have 3 roles and max_connections = 600. Need to setup max 10 ...
genderbee's user avatar
  • 191
1 vote
1 answer
758 views

LIMIT and OFFSET a complex query

I have a query generated by a ORM (Sequelize), i ran into an issue where sequelize fails, look at those issues. https://github.com/sequelize/sequelize/issues/7344 https://github.com/sequelize/...
Raman Shekhawat's user avatar
1 vote
3 answers
895 views

How to not allow to insert a new record if count of current records exceeds a specified limit

I have two tables as the following team `id` BIGINT PRIMARY KEY AUTO_INCREMENT, `name` VARCHAR(255) NOT NULL, `member_limit` INT NOT NULL team_member `id` BIGINT PRIMARY KEY AUTO_INCREMENT, `team_id` ...
Amjed Omar's user avatar
1 vote
0 answers
270 views

Mysql self Join query with Limit never terminates

I'm running an experiment with the query Select Distinct table_1.id1, table_2.id1 FROM image as table_1, image as table_2 WHERE table_1.id2 = table_2.id2 LIMIT K; When I run the query ...
Rainer Yuan's user avatar
0 votes
1 answer
106 views

updating n number of records mysql database

I want to update n number of records in table using a query like below, but it will return an error since in mysql, it is not allowed to use value after the limit key update producedItem pi inner ...
Wishwa Wickramasinghe's user avatar
0 votes
1 answer
345 views

MySQL apply LIMIT and OFFSET to a selected table, rather than to the result set

I have 3 tables as below. mysql> describe IDN_CONFIG_RESOURCE; +---------------+--------------+------+-----+-------------------+-------+ | Field | Type | Null | Key | Default ...
Nipun Thathsara's user avatar
0 votes
1 answer
70 views

Display Top X results for each unique value

I am trying to figure out how I can output any machine that has had the latest 3 backups be larger than 10GB. My SQL Table looks similar to the below table: ComputerID | BackupImageName | ...
Rmuell01's user avatar
0 votes
1 answer
994 views

How does adding LIMIT work with Where conditions in mysql?

In my database, there is only one record which satisfies the condition iv_title = 'ball skills'. Now I'm executing the following query : SELECT * FROM `imageAndVideo` WHERE `iv_title` = '...
rahim.nagori's user avatar
1 vote
0 answers
23 views

Set Maximum Tables In A Database [duplicate]

I need to set up a MySQL database with a maximum number of tables which can be created in it. For example, if I have my maximum at 5 tables for a single database, and someone attempts to create a 6th ...
CPSuperstore's user avatar
1 vote
1 answer
824 views

Distinct result with row_id for limit query

There are 2 tables: CREATE TABLE sample1 ( id int, name varchar, score int, mode int ) CREATE TABLE sample2 ( id int, mode int ... ) I need to select distinct name with MIN(score) and ...
Alex's user avatar
  • 113
3 votes
2 answers
27k views

Limit left join for multiple rows

Since MySql doesn't support main alias reference in subquery is a bit challenging to create query with multiple rows where you have to limit rows of left join tables. Let's overview simple example. ...
Arsenius's user avatar
  • 133
2 votes
2 answers
846 views

Predicting the primary keys exhaustion in MySQL based on rate of insertion

We are running out of primary keys for our table in production. We do not want that to occur again. So we need a mechanism to alert us when we are running out of primary keys based on the rate of ...
ali's user avatar
  • 21
1 vote
0 answers
855 views

SQL Server Express 2017 database size limitation

I have a database hosted on SQL Server Express 2017. The size was small like 200MB. Today I have copied 24GB tables to the same database from external database hosted on different server. The ...
Nano's user avatar
  • 139
0 votes
1 answer
216 views

MySQL logging max_questions resource

How would I know in MySQL if the user has exceeded his max_queries per hour? I know that I can see this error on the client side, but I just want to know that before client is reporting to me, ...
Ilie Soltanici's user avatar
0 votes
1 answer
6k views

Limit groups of results based on a column value

I'm not sure I formulated the question properly, but anyway. I have a table with level-2 comments, some of which, expectedly, have the same comment_parent column value. How do I make a SELECT query ...
COOLak's user avatar
  • 103
1 vote
1 answer
49 views

What happens if I load last 10 rows then next 10 after other rows are inserted?

What if I had a PHP script that had a pagination that loads last 10 rows then page two loaded next 10 in DESC order, but before loading next 10 on page 2, other 10 rows were added to the table? What ...
Casper X's user avatar
3 votes
2 answers
24k views

Alternate to use LIMIT in subquery in mysql?

I have 2 tables, Resource and views and I'm trying to get the list of all the items from Resource table whose ran_resId don't match with the ran_resId of last 2 records of views table. I'm trying to ...
Sumit's user avatar
  • 131
0 votes
1 answer
433 views

Does switching from INT to BIGINT entails significant downtime?

Hypothetically, if your INT column already has 4 billion rows, how long is the process of converting that column to BIGINT? I know this will depend on server resources but I just want to have a ...
IMB's user avatar
  • 169
1 vote
1 answer
414 views

Delete from table using FK columns, JOIN and LIMIT

This query below will never complete, since it always looks at the first 100,000 (user_type, user_ids). How can I write this to delete 100,000 records from the table with the FK reference (Product) to ...
Arthur M's user avatar
  • 121
14 votes
1 answer
14k views

Why *not* ERROR: index row size xxxx exceeds maximum 2712 for index "foo"?

We have repeatedly seen failing attempts to index columns with values exceeding a maximum size. Postgres 10 has this kind of error message for it: ERROR: index row size xxxx exceeds maximum 2712 for ...
Erwin Brandstetter's user avatar
20 votes
2 answers
25k views

MongoDB terminates when it runs out of memory

I have the following configuration: a host machine that runs three docker containers: MongoDB Redis A program using the previous two containers to store data Both Redis and MongoDB are used to ...
Simone Bronzini's user avatar
7 votes
2 answers
6k views

Postgres slow query with order by, index and limit

I am trying to improve the performance of a postgres(9.6) query. Here is my schema and table contains about 60 million rows. Column | Type | Modifiers -------...
Zeeshan's user avatar
  • 71
20 votes
5 answers
15k views

SQL Server Error 8632 due to over 100,000 entries in WHERE clause

My problem (or at least the error message) is very similar to query processor ran out of internal resources - extremely long sql query. My customer is working with an SQL select-query, containing a ...
Dominique's user avatar
  • 521
2 votes
1 answer
172 views

Is there a server option which limits the amount of rows returned by a remote query?

I have an issue where a system on our network is making a query (select * from table) which might result in 0 to 70k rows being returned. For large result sets, say around 50k, the calling system is ...
Beeblebrox's user avatar
1 vote
1 answer
289 views

Is it possible to limit concurrent aggregations in Mongo?

When clients makes certain requests, our service sends aggregation queries to Mongo. Some of these aggregations take longer than others. Usually this is fine, but occasionally multiple heavy ...
joeytwiddle's user avatar
5 votes
1 answer
4k views

Limits of applock in MS SQL Server

Microsoft SQL Server offers an arbitrary application-defined locking mechanism through the sp-getapplock command and related commands. The key, or resource_name, is specified as a string, a varchar ...
Basil Bourque's user avatar
5 votes
2 answers
40k views

MySQL LIMIT within JOIN

I have an 1:m association. symbols table has many rows in company_key_statistics table. company_key_statistics has column createdAt which is timestamp indicating when row has been created. I need to ...
Aren Hovsepyan's user avatar
4 votes
1 answer
2k views

PostgreSQL Size Quota on Table or Schema

How do one limit the size of a PostgreSQL table? (or schema) Limit in either bytes or rows would be OK. I'm starting to think that there's no easy and obvious solution. I have a lot of identical ...
kirilian's user avatar