Spring Data Jpa JPQL using inner join to select minimum priced holiday - spring

I am trying to find the minimum priced holiday for each month from each departure airport to a target destination airport from a table with over 1 million records. I have successfully created the required MySQL query :-
SELECT * FROM results r INNER JOIN (SELECT id,MIN(price) FROM results GROUP BY BulkLoaderRef) r2 ON r.id=r2.id ORDER BY r.departureDate, r.depAirportCode, r.resortID LIMIT 10
But I cannot find a valid JPQL syntax for this query?
Help please?
My table format is as follows :-
CREATE TABLE `results` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`HotelReference` varchar(128) NOT NULL DEFAULT '',
`HotelName` varchar(64) NOT NULL DEFAULT '',
`Resort` varchar(128) NOT NULL DEFAULT '',
`Description` longtext NOT NULL,
`Photo` varchar(255) NOT NULL DEFAULT '',
`OfferProcessType` varchar(1) NOT NULL DEFAULT 'A',
`TradingName` varchar(32) NOT NULL DEFAULT 'Heffernans Travel',
`OfferLabelDesc` varchar(16) NOT NULL DEFAULT 'EasyHolidays',
`DestinationName` varchar(128) NOT NULL DEFAULT '',
`DepAirportCode` varchar(3) NOT NULL DEFAULT '',
`TelephoneNumber` varchar(16) NOT NULL DEFAULT '021 230 0700',
`ReturnAirportCode` varchar(3) NOT NULL DEFAULT '',
`ArrivalAirportCode` varchar(3) NOT NULL DEFAULT '',
`ResortID` int(11) NOT NULL,
`ABTA` varchar(16) NOT NULL DEFAULT 'ABTA',
`ATOL` varchar(16) NOT NULL DEFAULT 'ATOL',
`OtherBonding` varchar(64) NOT NULL DEFAULT 'Agent for ATOL protected operator',
`BoardTypesShort` varchar(2) NOT NULL DEFAULT '',
`AccomodationShort` varchar(3) NOT NULL DEFAULT 'Htl',
`AllocationShort` varchar(3) DEFAULT '""',
`OperatorShort` varchar(16) NOT NULL DEFAULT 'EasyHolidays',
`DepartureDate` date NOT NULL,
`DepartureMonth` varchar(2) DEFAULT NULL,
`DepartureYear` varchar(4) DEFAULT NULL,
`Price` int(11) NOT NULL,
`ShareBasisAdult` int(11) DEFAULT '2',
`BulkLoaderRef` varchar(64) DEFAULT NULL,
`Email` varchar(64) DEFAULT '',
`PublicNotes` varchar(64) DEFAULT 'EasyHolidays',
`CCC` varchar(32) DEFAULT ' Credit Card Charges',
`TOD` varchar(16) DEFAULT '',
`DCC` varchar(16) DEFAULT '',
`AMEX` varchar(16) DEFAULT '',
`CDW` varchar(16) DEFAULT '',
`BookingFee` double DEFAULT NULL,
`AccomodationName` varchar(64) NOT NULL DEFAULT '',
`duration` int(11) NOT NULL DEFAULT '0',
`ShareBasisChild` int(11) DEFAULT '2',
`Rating` varchar(16) NOT NULL DEFAULT '',
`OfferLink` varchar(16) NOT NULL DEFAULT '',
`AccomodationRef` varchar(128) NOT NULL DEFAULT '',
`Transfers` varchar(32) NOT NULL DEFAULT '',
`OperatorsRating` varchar(32) NOT NULL DEFAULT '',
`QuoteRef` varchar(64) NOT NULL DEFAULT '',
`Url` varchar(128) NOT NULL DEFAULT '',
`OutDepTime` varchar(16) NOT NULL DEFAULT '',
`OutArrTime` varchar(16) NOT NULL DEFAULT '',
`InDepTime` varchar(16) NOT NULL DEFAULT '',
`InArrTime` varchar(16) NOT NULL DEFAULT '',
PRIMARY KEY (`id`),
UNIQUE KEY `HotelReference` (`HotelReference`),
KEY `BulkLoaderRef` (`BulkLoaderRef`),
KEY `Price` (`Price`)
) ENGINE=InnoDB AUTO_INCREMENT=1091073 DEFAULT CHARSET=utf8;

JPQL doesn't support sub-queries for JOIN statements. With that said, I would suggest that you move the subquery of your JOIN into a view. Then it becomes a simple JPQL statement.
Move subquery into a view:
CREATE VIEW min_price_view AS
SELECT id,MIN(price) FROM results GROUP BY BulkLoaderRef;
Then replace in query:
SELECT
*
FROM
results r
INNER JOIN
min_price_view r2 ON r.id=r2.id
ORDER BY
r.departureDate, r.depAirportCode, r.resortID
LIMIT 10
At this point, it becomes very simple to convert it to JPQL.

Related

Attempt to define a second primary key with IF NOT EXISTS

Why is this statement failing despite the "IF NOT EXISTS" clause?
org.h2.jdbc.JdbcSQLSyntaxErrorException: Attempt to define a second primary key; SQL statement:
ALTER TABLE QRTZ_CALENDARS
ADD CONSTRAINT IF NOT EXISTS PK_QRTZ_CALENDARS PRIMARY KEY ( SCHED_NAME, CALENDAR_NAME ) [90017-212]
H2 is run in memory mode jdbc:h2:mem:quartz;INIT=RUNSCRIPT FROM 'classpath:tables_h2.sql'
CREATE TABLE IF NOT EXISTS QRTZ_CALENDARS (
SCHED_NAME VARCHAR(120) NOT NULL,
CALENDAR_NAME VARCHAR (200) NOT NULL ,
CALENDAR IMAGE NOT NULL
);
If I move the PK definition into table definition the error goes away.
The script is
CREATE TABLE IF NOT EXISTS QRTZ_CALENDARS (
SCHED_NAME VARCHAR(120) NOT NULL,
CALENDAR_NAME VARCHAR (200) NOT NULL ,
CALENDAR IMAGE NOT NULL
);
CREATE TABLE IF NOT EXISTS QRTZ_CRON_TRIGGERS (
SCHED_NAME VARCHAR(120) NOT NULL,
TRIGGER_NAME VARCHAR (200) NOT NULL ,
TRIGGER_GROUP VARCHAR (200) NOT NULL ,
CRON_EXPRESSION VARCHAR (120) NOT NULL ,
TIME_ZONE_ID VARCHAR (80)
);
CREATE TABLE IF NOT EXISTS QRTZ_FIRED_TRIGGERS (
SCHED_NAME VARCHAR(120) NOT NULL,
ENTRY_ID VARCHAR (95) NOT NULL ,
TRIGGER_NAME VARCHAR (200) NOT NULL ,
TRIGGER_GROUP VARCHAR (200) NOT NULL ,
INSTANCE_NAME VARCHAR (200) NOT NULL ,
FIRED_TIME BIGINT NOT NULL ,
SCHED_TIME BIGINT NOT NULL ,
PRIORITY INTEGER NOT NULL ,
STATE VARCHAR (16) NOT NULL,
JOB_NAME VARCHAR (200) NULL ,
JOB_GROUP VARCHAR (200) NULL ,
IS_NONCONCURRENT BOOLEAN NULL ,
REQUESTS_RECOVERY BOOLEAN NULL
);
CREATE TABLE IF NOT EXISTS QRTZ_PAUSED_TRIGGER_GRPS (
SCHED_NAME VARCHAR(120) NOT NULL,
TRIGGER_GROUP VARCHAR (200) NOT NULL
);
CREATE TABLE IF NOT EXISTS QRTZ_SCHEDULER_STATE (
SCHED_NAME VARCHAR(120) NOT NULL,
INSTANCE_NAME VARCHAR (200) NOT NULL ,
LAST_CHECKIN_TIME BIGINT NOT NULL ,
CHECKIN_INTERVAL BIGINT NOT NULL
);
CREATE TABLE IF NOT EXISTS QRTZ_LOCKS (
SCHED_NAME VARCHAR(120) NOT NULL,
LOCK_NAME VARCHAR (40) NOT NULL
);
CREATE TABLE IF NOT EXISTS QRTZ_JOB_DETAILS (
SCHED_NAME VARCHAR(120) NOT NULL,
JOB_NAME VARCHAR (200) NOT NULL ,
JOB_GROUP VARCHAR (200) NOT NULL ,
DESCRIPTION VARCHAR (250) NULL ,
JOB_CLASS_NAME VARCHAR (250) NOT NULL ,
IS_DURABLE BOOLEAN NOT NULL ,
IS_NONCONCURRENT BOOLEAN NOT NULL ,
IS_UPDATE_DATA BOOLEAN NOT NULL ,
REQUESTS_RECOVERY BOOLEAN NOT NULL ,
JOB_DATA IMAGE NULL
);
CREATE TABLE IF NOT EXISTS QRTZ_SIMPLE_TRIGGERS (
SCHED_NAME VARCHAR(120) NOT NULL,
TRIGGER_NAME VARCHAR (200) NOT NULL ,
TRIGGER_GROUP VARCHAR (200) NOT NULL ,
REPEAT_COUNT BIGINT NOT NULL ,
REPEAT_INTERVAL BIGINT NOT NULL ,
TIMES_TRIGGERED BIGINT NOT NULL
);
CREATE TABLE IF NOT EXISTS QRTZ_SIMPROP_TRIGGERS (
SCHED_NAME VARCHAR(120) NOT NULL,
TRIGGER_NAME VARCHAR(200) NOT NULL,
TRIGGER_GROUP VARCHAR(200) NOT NULL,
STR_PROP_1 VARCHAR(512) NULL,
STR_PROP_2 VARCHAR(512) NULL,
STR_PROP_3 VARCHAR(512) NULL,
INT_PROP_1 INTEGER NULL,
INT_PROP_2 INTEGER NULL,
LONG_PROP_1 BIGINT NULL,
LONG_PROP_2 BIGINT NULL,
DEC_PROP_1 NUMERIC(13,4) NULL,
DEC_PROP_2 NUMERIC(13,4) NULL,
BOOL_PROP_1 BOOLEAN NULL,
BOOL_PROP_2 BOOLEAN NULL
);
CREATE TABLE IF NOT EXISTS QRTZ_BLOB_TRIGGERS (
SCHED_NAME VARCHAR(120) NOT NULL,
TRIGGER_NAME VARCHAR (200) NOT NULL ,
TRIGGER_GROUP VARCHAR (200) NOT NULL ,
BLOB_DATA IMAGE NULL
);
CREATE TABLE IF NOT EXISTS QRTZ_TRIGGERS (
SCHED_NAME VARCHAR(120) NOT NULL,
TRIGGER_NAME VARCHAR (200) NOT NULL ,
TRIGGER_GROUP VARCHAR (200) NOT NULL ,
JOB_NAME VARCHAR (200) NOT NULL ,
JOB_GROUP VARCHAR (200) NOT NULL ,
DESCRIPTION VARCHAR (250) NULL ,
NEXT_FIRE_TIME BIGINT NULL ,
PREV_FIRE_TIME BIGINT NULL ,
PRIORITY INTEGER NULL ,
TRIGGER_STATE VARCHAR (16) NOT NULL ,
TRIGGER_TYPE VARCHAR (8) NOT NULL ,
START_TIME BIGINT NOT NULL ,
END_TIME BIGINT NULL ,
CALENDAR_NAME VARCHAR (200) NULL ,
MISFIRE_INSTR SMALLINT NULL ,
JOB_DATA IMAGE NULL
);
ALTER TABLE QRTZ_CALENDARS ADD
CONSTRAINT IF NOT EXISTS PK_QRTZ_CALENDARS PRIMARY KEY
(
SCHED_NAME,
CALENDAR_NAME
);
ALTER TABLE QRTZ_CRON_TRIGGERS ADD
CONSTRAINT IF NOT EXISTS PK_QRTZ_CRON_TRIGGERS PRIMARY KEY
(
SCHED_NAME,
TRIGGER_NAME,
TRIGGER_GROUP
);
ALTER TABLE QRTZ_FIRED_TRIGGERS ADD
CONSTRAINT IF NOT EXISTS PK_QRTZ_FIRED_TRIGGERS PRIMARY KEY
(
SCHED_NAME,
ENTRY_ID
);
ALTER TABLE QRTZ_PAUSED_TRIGGER_GRPS ADD
CONSTRAINT IF NOT EXISTS PK_QRTZ_PAUSED_TRIGGER_GRPS PRIMARY KEY
(
SCHED_NAME,
TRIGGER_GROUP
);
ALTER TABLE QRTZ_SCHEDULER_STATE ADD
CONSTRAINT IF NOT EXISTS PK_QRTZ_SCHEDULER_STATE PRIMARY KEY
(
SCHED_NAME,
INSTANCE_NAME
);
ALTER TABLE QRTZ_LOCKS ADD
CONSTRAINT IF NOT EXISTS PK_QRTZ_LOCKS PRIMARY KEY
(
SCHED_NAME,
LOCK_NAME
);
ALTER TABLE QRTZ_JOB_DETAILS ADD
CONSTRAINT IF NOT EXISTS PK_QRTZ_JOB_DETAILS PRIMARY KEY
(
SCHED_NAME,
JOB_NAME,
JOB_GROUP
);
ALTER TABLE QRTZ_SIMPLE_TRIGGERS ADD
CONSTRAINT IF NOT EXISTS PK_QRTZ_SIMPLE_TRIGGERS PRIMARY KEY
(
SCHED_NAME,
TRIGGER_NAME,
TRIGGER_GROUP
);
ALTER TABLE QRTZ_SIMPROP_TRIGGERS ADD
CONSTRAINT IF NOT EXISTS PK_QRTZ_SIMPROP_TRIGGERS PRIMARY KEY
(
SCHED_NAME,
TRIGGER_NAME,
TRIGGER_GROUP
);
ALTER TABLE QRTZ_TRIGGERS ADD
CONSTRAINT IF NOT EXISTS PK_QRTZ_TRIGGERS PRIMARY KEY
(
SCHED_NAME,
TRIGGER_NAME,
TRIGGER_GROUP
);
ALTER TABLE QRTZ_CRON_TRIGGERS ADD
CONSTRAINT IF NOT EXISTS FK_QRTZ_CRON_TRIGGERS_QRTZ_TRIGGERS FOREIGN KEY
(
SCHED_NAME,
TRIGGER_NAME,
TRIGGER_GROUP
) REFERENCES QRTZ_TRIGGERS (
SCHED_NAME,
TRIGGER_NAME,
TRIGGER_GROUP
) ON DELETE CASCADE;
ALTER TABLE QRTZ_SIMPLE_TRIGGERS ADD
CONSTRAINT IF NOT EXISTS FK_QRTZ_SIMPLE_TRIGGERS_QRTZ_TRIGGERS FOREIGN KEY
(
SCHED_NAME,
TRIGGER_NAME,
TRIGGER_GROUP
) REFERENCES QRTZ_TRIGGERS (
SCHED_NAME,
TRIGGER_NAME,
TRIGGER_GROUP
) ON DELETE CASCADE;
ALTER TABLE QRTZ_SIMPROP_TRIGGERS ADD
CONSTRAINT IF NOT EXISTS FK_QRTZ_SIMPROP_TRIGGERS_QRTZ_TRIGGERS FOREIGN KEY
(
SCHED_NAME,
TRIGGER_NAME,
TRIGGER_GROUP
) REFERENCES QRTZ_TRIGGERS (
SCHED_NAME,
TRIGGER_NAME,
TRIGGER_GROUP
) ON DELETE CASCADE;
ALTER TABLE QRTZ_TRIGGERS ADD
CONSTRAINT IF NOT EXISTS FK_QRTZ_TRIGGERS_QRTZ_JOB_DETAILS FOREIGN KEY
(
SCHED_NAME,
JOB_NAME,
JOB_GROUP
) REFERENCES QRTZ_JOB_DETAILS (
SCHED_NAME,
JOB_NAME,
JOB_GROUP
);
COMMIT;
The error only happens when concurrent connections are established.
If I set the pool size to 1 it does not occur.
If I set the pool size to 2 I see it logged once.
If I set the pool size to 3 I see it logged twice.
The error seems to be gone when the connection pool retries.
It all looks like a concurrency bug in H2
IF NOT EXISTS checks only presence of constraint with exactly the same name. This exception indicates that your table already has a primary key constraint with the same or other set of columns, but with different name.
If you're sure that this table either has a primary key constraint on these two columns with unknown name or doesn't have a primary key constraint at all, you can replace your command with the following one:
EXECUTE IMMEDIATE
CASE WHEN NOT EXISTS (
SELECT * FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS
WHERE TABLE_NAME = 'QRTZ_CALENDARS' AND CONSTRAINT_TYPE = 'PRIMARY KEY')
THEN 'ALTER TABLE QRTZ_CALENDARS ADD CONSTRAINT PK_QRTZ_CALENDARS PRIMARY KEY (SCHED_NAME, CALENDAR_NAME)'
ELSE ''
END;

How can we replace value in unix using sed after a certain pattern

I Have a file with below data, in which I want to replace everything in line after a Default nextval with AUTO_INCREMENT
I tries sed command but it didn't help
Data:
`id` bigint(20) NOT NULL DEFAULT nextval(`xchange_finance`.`seq_cancelled_contract_zendesk_publishing_failure`),
`id` bigint(20) NOT NULL DEFAULT nextval(`xchange_finance`.`seq_invoice`),
`id` bigint(20) NOT NULL DEFAULT nextval(`xchange_finance`.`seq_invoice_attachment`),
`id` bigint(20) NOT NULL DEFAULT nextval(`xchange_finance`.`seq_invoice_line_item`),
expected:
`id` bigint(20) NOT NULL AUTO_INCREMENT ,
`id` bigint(20) NOT NULL AUTO_INCREMENT ,
`id` bigint(20) NOT NULL AUTO_INCREMENT ,
`id` bigint(20) NOT NULL AUTO_INCREMENT
tried something like below but it didn't work
sed -e 's/^DEFAULT nextval.*$/AUTO_INCREMENT ,/g' test

MySQL inner join and order by bad performance

I have two tables. products and product_images.
Products: ~ 6 276 445 rows.
ProductImages: ~ 22 888 685 rows.
Table definitions:
products
CREATE TABLE `products` (
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`unique_id` varchar(32) COLLATE utf8mb4_unicode_ci NOT NULL,
`feed_id` bigint(20) unsigned NOT NULL,
`feed_item_id` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL,
`item_group_id` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL,
`name` varchar(200) COLLATE utf8mb4_unicode_ci NOT NULL,
`slug` varchar(200) COLLATE utf8mb4_unicode_ci NOT NULL,
`description` text COLLATE utf8mb4_unicode_ci NOT NULL,
`categorytext` text COLLATE utf8mb4_unicode_ci NOT NULL,
`categorytext_hash` varchar(32) COLLATE utf8mb4_unicode_ci NOT NULL,
`manufacturer` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL,
`product_url` text COLLATE utf8mb4_unicode_ci NOT NULL,
`price_vat` float(12,2) DEFAULT NULL,
`price_vat_old` float(12,2) DEFAULT NULL,
`vat` tinyint(4) DEFAULT NULL,
`discount_percentage` tinyint(4) NOT NULL DEFAULT 0,
`image_source_url` text COLLATE utf8mb4_unicode_ci NOT NULL,
`image_filename` varchar(200) COLLATE utf8mb4_unicode_ci NOT NULL,
`gtin` varchar(14) COLLATE utf8mb4_unicode_ci NOT NULL,
`ean` varchar(13) COLLATE utf8mb4_unicode_ci NOT NULL,
`isbn` varchar(13) COLLATE utf8mb4_unicode_ci NOT NULL,
`upc` varchar(12) COLLATE utf8mb4_unicode_ci NOT NULL,
`mpn` varchar(70) COLLATE utf8mb4_unicode_ci NOT NULL,
`missing_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
`created_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
`updated_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
`deleted_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
`project_1` tinyint(4) NOT NULL DEFAULT 0,
`project_2` tinyint(4) NOT NULL DEFAULT 0,
PRIMARY KEY (`id`),
UNIQUE KEY `unique_id_UNIQUE` (`unique_id`),
KEY `feed_id_updated_at` (`feed_id`,`updated_at`),
KEY `feed_id` (`feed_id`),
KEY `feed_id_missing_at` (`feed_id`,`missing_at`),
KEY `feed_id_categorytext_hash_id` (`feed_id`,`categorytext_hash`,`id`),
KEY `categorytext_hash` (`categorytext_hash`),
KEY `missing_at_deleted_at_categorytext_hash_feed_id_id` (`missing_at`,`deleted_at`,`categorytext_hash`,`feed_id`,`id`),
KEY `project_1_id` (`project_1`,`id`),
KEY `project_2_id` (`project_2`,`id`),
KEY `project_1` (`project_1`),
KEY `project_2` (`project_2`),
CONSTRAINT `fk_products_feeds` FOREIGN KEY (`feed_id`) REFERENCES `feeds` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=122268834 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
product_images
CREATE TABLE `product_images` (
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`product_unique_id` varchar(32) COLLATE utf8mb4_unicode_ci NOT NULL,
`unique_id` varchar(32) COLLATE utf8mb4_unicode_ci NOT NULL,
`feed_id` bigint(20) unsigned NOT NULL,
`image_source_url` text COLLATE utf8mb4_unicode_ci NOT NULL,
`image_filename` varchar(200) COLLATE utf8mb4_unicode_ci NOT NULL,
`created_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
`updated_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
`deleted_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
PRIMARY KEY (`id`),
UNIQUE KEY `unique_id_UNIQUE` (`unique_id`),
KEY `feed_id_updated_at` (`feed_id`,`updated_at`),
KEY `product_unique_id` (`product_unique_id`),
KEY `product_unique_id_id` (`product_unique_id`,`id`),
CONSTRAINT `fk_product_images_products1` FOREIGN KEY (`product_unique_id`) REFERENCES `products` (`unique_id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=333584333 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
My Query without ORDER BY
SELECT IMG.id
FROM products PR
INNER JOIN product_images IMG on IMG.product_unique_id = PR.unique_id
WHERE
PR.project_1 = 1
-- ORDER BY IMG.id
LIMIT 1000 OFFSET 0
Duration: 0.016 sec
EXPLAIN:
id|select_type|table|type|possible_keys |key |key_len|ref |rows |Extra |
--+-----------+-----+----+---------------------------------------+-----------------+-------+-----------------------------+------+-----------+
1|SIMPLE |PR |ref |unique_id_UNIQUE,project_1_id,project_1|project_1 |1 |const |286960| |
1|SIMPLE |IMG |ref |product_unique_id,product_unique_id_id |product_unique_id|130 |products-storage.PR.unique_id|2 |Using index|
My Query with ORDER BY
SELECT IMG.id
FROM products PR
INNER JOIN product_images IMG on IMG.product_unique_id = PR.unique_id
WHERE
PR.project_1 = 1
ORDER BY IMG.id
LIMIT 1000 OFFSET 0
Duration 17.922 sec
EXPLAIN:
id|select_type|table|type|possible_keys |key |key_len|ref |rows |Extra |
--+-----------+-----+----+---------------------------------------+-----------------+-------+-----------------------------+------+-------------------------------+
1|SIMPLE |PR |ref |unique_id_UNIQUE,project_1_id,project_1|project_1 |1 |const |286960|Using temporary; Using filesort|
1|SIMPLE |IMG |ref |product_unique_id,product_unique_id_id |product_unique_id|130 |products-storage.PR.unique_id|2 |Using index |
Problem
Query with order by is too slow. Is there a way to speed up query with some index or server settings? I need order by for pagination.
The goal is to select all images for project and send them through the api to another server.
I'm using mariadb 10.8.2
Server is on SSD with 8GB RAM

C# Error ORA 00907: Missing Right Parenthesis

My error:
ORA 00907: Missing Right Parenthesis
My code:
CREATE TABLE TBL_TD_USER
(
USER_ID INTEGER(10) NOT NULL,
USER_NAME VARCHAR2(20) NOT NULL,
PASSWORD VARCHAR2(20) NOT NULL,
CREATED_BY VARCHAR2(20) NOT NULL,
CREATED_DATE DATE NOT NULL,
MODIFIED_BY VARCHAR2(20) NOT NULL,
MODIFIED_DATE DATE NOT NULL,
IS_ACTIVE CHARACTER(1) NOT NULL,
DESCRIPTION VARCHAR2(200) NOT NULL,
CONSTRAINT TBL_TD_USER PRIMARY KEY (USER_ID)
);
This works:
CREATE TABLE TBL_TD_USER
(
USER_ID INTEGER NOT NULL ,
USER_NAME VARCHAR2(20) NOT NULL,
PASSWORD VARCHAR2(20) NOT NULL,
CREATED_BY VARCHAR2(20) NOT NULL,
CREATED_DATE DATE NOT NULL,
MODIFIED_BY VARCHAR2(20) NOT NULL,
MODIFIED_DATE DATE NOT NULL,
IS_ACTIVE VARCHAR2(1) NOT NULL,
DESCRIPTION VARCHAR2(200) NOT NULL,
CONSTRAINT TBL_TD_USER PRIMARY KEY (USER_ID)
);
There's no variable type named CHARACTER in oracle, as an alternative, you to use VARCHAR2 with length value in parenthesis.
You can use INTEGER type without length.
demo

Error MySQL #1064 at 1 Line

I need to create table for my sql database and i have a 1 error sucking my work, anyone can help me for i fix that error:
[sql]CREATE TABLE `z_ots_comunication` (
`id` int(0) NOT NULL DEFAULT 0
`name` varchar(255) NOT NULL,
`type` varchar(255) NOT NULL,
`action` varchar(255) NOT NULL,
`param1` varchar(255) NOT NULL,
`param2` varchar(255) NOT NULL,
`param3` varchar(255) NOT NULL,
`param4` varchar(255) NOT NULL,
`param5` varchar(255) NOT NULL,
`param6` varchar(255) NOT NULL,
`param7` varchar(255) NOT NULL,
`delete_it` int(2) NOT NULL default '1',
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
Msg of MySQL:
1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '[sql]CREATE TABLE z_ots_comunication (
id int(0) NOT NULL DEFAULT 0
name' at line 1
You forgot to put a comma after the ID column:
CREATE TABLE `z_ots_comunication` (
`id` int(0) NOT NULL DEFAULT 0,
`name` varchar(255) NOT NULL,
`type` varchar(255) NOT NULL,
...
Try This code u have missed a semi colon before name filed
CREATE TABLE `z_ots_comunication` (
`id` int(0) NOT NULL DEFAULT 0,
`name` varchar(255) NOT NULL,
`type` varchar(255) NOT NULL,
`action` varchar(255) NOT NULL,
`param1` varchar(255) NOT NULL,
`param2` varchar(255) NOT NULL,
`param3` varchar(255) NOT NULL,
`param4` varchar(255) NOT NULL,
`param5` varchar(255) NOT NULL,
`param6` varchar(255) NOT NULL,
`param7` varchar(255) NOT NULL,
`delete_it` int(2) NOT NULL default '1',
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1

Resources